How about this?

*{{total = 0}}*








*{{for c in children:}}<tr>    <td>{{=c.parent.full_names}}</td>    
<td>{{=c.childs_names}}</td>    <td>{{=c.policy_cover.policy_name}}</td>    
<td>{{=c.policy_cover.premium}}</td>    {{total 
+=c.policy_cover.premium}}</tr>{{pass}}*
*<tr>*
*    <td>*
*        TOTAL PREMIUM: {{=total}}*
*    </td>*
*</tr>*


On Monday, April 11, 2022 at 4:56:37 AM UTC-5 mostwanted wrote:

> I have a problem that i'm failing to fix, i want to calculate the sum of 
> all premiums for all tables in a client's account. A client is paying  
> insurance for his kids & his parents, i want to display this information in 
> the view in an html table and be able to calculate his total premium for 
> both his kids and his parents, the problem is when i try to add them up it 
> picks up only 1 value from the children's table which is the value last 
> entered and 1 value in the parents table.
>
> When i try *sum_values=db.children.policy_cover.premium.sum() *i get an 
> error that:
> *<class 'AttributeError'> 'Field' object has no attribute 'premium'*
>
> *TABLES*
>
>
>
>
>
>
>
> *db.define_table('children_policy',                Field('policy_name'),  
>               Field('premium', 'double'),                
> format='%(policy_name)s')db.define_table('client',                
> Field('full_names'),                format='%(full_names)s')*
>
>
>
>
>
> *db.define_table('children',                Field('parent', 'reference 
> client'),                Field('childs_names'),                
> Field('policy_cover', 'reference children_policy')*
>
> *CONTROLLERS*
>
>
>
>
> *def index():    clients=db(db.client).select()    
> children=db(db.children).select(db.children.ALL)    
> parent=db(db.parent).select(db.parent.ALL)    return locals()*
>
>
> *VIEW*
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> *<table><th>POLICY OWNER</th>    <th>CHILD</th>    <th>POLICY</th>    
> <th>PREMIUM</th><tr>{{for c in children:}}    
> <td>{{=c.parent.full_names}}</td>    <td>{{=c.childs_names}}</td>    
> <td>{{=c.policy_cover.policy_name}}</td>    
> <td>{{=c.policy_cover.premium}}</td>    </tr>    
> {{total=sum(c.policy_cover.premium)}}{{pass}}    {{pass}}                  
>   <tr><td>TOTAL PREMIUM:{{=total}}</td></tr>    {{pass}}</table>*
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/3f2edd34-5aeb-4a0b-b4f9-938bd34306ddn%40googlegroups.com.

Reply via email to