Determinign what information get displayed based on their content

33 views
Skip to first unread message

mostwanted

unread,
Sep 12, 2019, 11:29:48 AM9/12/19
to web2py-users
In my database i have items i am selling, one of the fields is quantity which refers to the number of items still available for purchase, what i want is for that item not to be displayed when quantity reaches 0. Initially i had the items get deleted when quantity is zero until i realized that the sales details of that item in the sales table are also deleted since it is referenced from the product table where its being deleted. I had to come up with a better solution apart from deleting, i tried this below, where its colored:

{{for p in products:}}
       
{{if p.product_type=="Earrings":}}
<script>
            jQuery
(document).ready(function()
                                   
{
               
if (jQuery({{p.amount==0}}))
                             
{
                 
const id = jQuery(this).data('id');
                jQuery
('#'+id).hide();
                             
}
           
});
       
</script>

<div class="clothes" data-id="{{=p.id}}">

    <h4 style="color: #ff69b4;">{{=p.name}}</
h4>
   
<h7 style="color: #ff69b4;">{{=p.amount}} available in stock</h7>
    <h5>
        <span style="color: aqua; font-weight: bold;">{{=MoneyFormat(p.price)}}</
span>
   
</h5>
    <img class="magnify" src="{{=URL('download',args=p.image)}}" height="200px"/
>
   
<br />
   
{{=A('REMOVE',callback=URL('cart_callback',vars=dict(id=p.id,action='sub')),target='item%s'%p.id,_class='button pill')}} - <span id="{{='item%s'%p.id}}" style="font-weight: bold; color: red;">{{=session.cart.get(p.id,0)}}</span> in cart - {{=A('ADD',callback=URL('cart_callback',vars=dict(id=p.id,action='add')),target='item%s'%p.id,_class='button pill')}}
   
<br />
   
<span style="font-size:12px;font-weight: bold; color: #ff69b4;">Click the image to enlarge</span>
<br /
>
</div>
{{pass}}

But this is a desperate move, if data-id={{=p.id}} was in a link then something would probubly happen, maybe, i feel only a pure python script could work here.
Is there a way i could choose what gets displayed in the view & what doesn't get displayed from the database table based on its content using only python??

Regards;

Mostwanted

Paco Bernal

unread,
Sep 15, 2019, 7:01:02 AM9/15/19
to web2py-users


Is there a way i could choose what gets displayed in the view & what doesn't get displayed from the database table based on its content using only python??



{{for p in products:}}
<tr class="{{='hidden' if p.Quantity==0 else ''}}">
 
<td>{{=p.whatever}}</td>
</tr>
{{pass}}




Paco Bernal

unread,
Sep 15, 2019, 7:03:16 AM9/15/19
to web2py-users

Is there a way i could choose what gets displayed in the view & what doesn't get displayed from the database table based on its content using only python??

{{for p in products:}}
{{if p.Quantity>0:}}
<tr>

 
<td>{{=p.whatever}}</td>
</tr>
{{pass}}
{{pass}}

Two ways for doing that :)

mostwanted

unread,
Sep 16, 2019, 1:24:28 AM9/16/19
to web2py-users
Thanks again Paco Bernal, I can finally move on to other things.

Regards;

Mostwanted
Reply all
Reply to author
Forward
0 new messages