Of course, that's only if you add or delete one record at a time.

On Wednesday, January 15, 2014 12:09:11 AM UTC-5, Anthony wrote:
>
> db.thing._after_insert.append(lambda f,id: db(db.person.id
>> ==f['owner_id']).update(total_items=len(db(db.thing.owner_id==f['owner_id']).select())))
>> from pprint import pprint
>> db.thing._before_delete.append(lambda s: db(db.person.id
>> ==s.select().first()['owner_id']).update(total_items=db(db.thing.owner_id==s.select().first()['owner_id']).count()))
>>
>
> Note, to simplify, you can do .update(total_items=db.person.total_items + 
> 1) and .update(total_items=db.person.total_items - 1).
>
> Anthony
>

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to