That definitely looks like it should work according to the book.

What do you get when you do it exactly like the book?

>>> db.define_table('item',
        Field 
<http://web2py.com/book/default/docstring/Field>('unit_price','double'),
        Field 
<http://web2py.com/book/default/docstring/Field>('quantity','integer'),
        Field <http://web2py.com/book/default/docstring/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


What version of Web2py? Do you get different behavior if you pull the 
compute out of the table def?

db.item.total_price.compute = lambda r: r['unit_price']*r['quantity']

How about: 
db.item.total_price.compute = lambda r: float(r['unit_price']) * 
float(r['quantity'])

Reply via email to