[web2py] Re: Is there a way to have a field in one table be computed by a field in another table?

2014-01-14 Thread Anthony
As noted in the book, the _before_ callbacks must return falsey values, or the operation will be aborted. So, you can either write a full function (that returns False) instead of using a lambda, or do something like: lambda s: db(...).update(...) and False which will return the value False. An

[web2py] Re: Is there a way to have a field in one table be computed by a field in another table?

2014-01-14 Thread Anthony
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 ppri

[web2py] Re: Is there a way to have a field in one table be computed by a field in another table?

2014-01-14 Thread Anthony
> > 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

[web2py] Re: Is there a way to have a field in one table be computed by a field in another table?

2014-01-14 Thread Apple Mason
Yeah, that thread says to use _before_delete, and it fits this use case. Can you verify if what I'm seeing about the delete is correct? The _before_delete is causing the admin panel to not delete the record for some reason. Is it a bug? I'm using web2py 2.7.4 stable On Tuesday, January 14, 201

[web2py] Re: Is there a way to have a field in one table be computed by a field in another table?

2014-01-14 Thread 黄祥
for after delete callback, please check this discussion https://groups.google.com/forum/#!msg/web2py/M4_5THMHzH0/r9aXH-k8eJQJ best regards, stifan -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/

[web2py] Re: Is there a way to have a field in one table be computed by a field in another table?

2014-01-14 Thread Apple Mason
I read through the link you show me. I'm using _before_delete now, since doing s.select() returns 0 rows since it's already been deleted. I'm not sure how to deal with sets in _after_delete. Here is my updated models: db.define_table('person', Field('name'),

[web2py] Re: Is there a way to have a field in one table be computed by a field in another table?

2014-01-14 Thread 黄祥
another way around i think you can do it in web form using oncreate, onupdate and ondelete. and for delete callback, please check this discussion : https://groups.google.com/forum/#!topic/web2py/didLpxEKT38 reference for oncreate, onupdate and ondelete, please check this discussion : https://gro

[web2py] Re: Is there a way to have a field in one table be computed by a field in another table?

2014-01-14 Thread Apple Mason
Thanks, I came up with this: 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( It works, but is there is a better way to do this? Also, can someone help me with _after_delete? _after_delete gives me

[web2py] Re: Is there a way to have a field in one table be computed by a field in another table?

2014-01-14 Thread Anthony
If you want db.person to be updated upon changes to db.thing, instead of a computed field in db.person, you probably want to create _after_insert and _after_update callbacks for db.thing (see http://www.web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#before-and-after-callba