i going adding fields table schema in web2py using db.py file...
i want add 3 new fields, 2 datetime , 1 field show timespan of other 2 fields...
q: how can define 3rd field automatically populated difference of 2 datetime values row?
try following:
>>> db.define_table('item', field('unit_price','double'), field('quantity','integer'), field('total_price', compute=lambda r: r['unit_price'] * r['quantity'])) >>> r = db.item.insert(unit_price=1.99, quantity=5) >>> print r.total_price 9.95
see http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#computed-fields
Comments
Post a Comment