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>