Hi, The problem was, that I was not selecting the field *item.quantity* , which is needed to calculate virtual field's value..
so I need to do db.*item.quantity*.readable = False grid=SQLFORM.grid(db.item.id>0, fields=[db.item.unit_price, db.item.total_price, db.*item.quantity* ] ) ps.: 1st argument to grid can be table or query. On Thursday, December 29, 2016 at 3:27:44 PM UTC+2, Áureo Dias Neto wrote: > > The SQLFORM expect to receive, an table, not a query.. > > What's the name of your table? just put the name of the table on the first > argumment, and filter with 'fields' the fields you want to show. > > Just change: > grid=SQLFORM.grid(db.item.id>0, fields=[db.item.unit_price, > db.item.total_price ] ) > To: > grid=SQLFORM.grid(db.Y <http://db.item.id/>OUR_TABLE, > fields=[db.item.unit_price, db.item.total_price ] ) > > 2016-12-29 11:19 GMT-02:00 Jurgis Pralgauskis <[email protected] > <javascript:>>: > >> Hi, >> >> I try to use virtual fields as in example >> >> http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer?search=virtual#New-style-virtual-fields >> >> >> db.item.total_price = Field.Virtual('total_price', >> lambda row: row.item.unit_price * >> row.item.quantity) >> >> But how can I list virtual field in grid fields? >> >> grid=SQLFORM.grid(db.item.id>0, fields=[db.item.unit_price, >> db.item.total_price ] ) >> >> gives error >> >> web2py™ Version 2.14.6-stable+timestamp.2016.05.10.00.21.47 Traceback >> >> Traceback (most recent call last): >> File "/home/jurgis/dev/web2py_src/gluon/restricted.py", line 227, in >> restricted >> exec ccode in environment >> File >> "/home/jurgis/dev/web2py_src/applications/app/controllers/plugin_search_form.py" >> >> <http://localhost:8001/admin/default/edit/app/controllers/plugin_search_form.py>, >> line 247, in <module> >> File "/home/jurgis/dev/web2py_src/gluon/globals.py", line 417, in <lambda> >> self._caller = lambda f: f() >> File >> "/home/jurgis/dev/web2py_src/applications/app/controllers/plugin_search_form.py" >> >> <http://localhost:8001/admin/default/edit/app/controllers/plugin_search_form.py>, >> line 50, in test_virtual_field >> grid=SQLFORM.grid(db.item.id>0, fields=[db.item.unit_price, >> db.item.total_price ] ) >> File "/home/jurgis/dev/web2py_src/gluon/sqlhtml.py", line 2758, in grid >> value = row[str(field)] >> File "/home/jurgis/dev/web2py_src/gluon/packages/dal/pydal/objects.py", >> line 76, in __getitem__ >> raise KeyError >> KeyError >> >> >> >> >> ps.: listing all fields would work, but I don't need all : >> grid=SQLFORM.grid(db.item.id>0 ) >> >> or should I use readable = False for the ones I want to hide? >> >> -- >> Jurgis Pralgauskis >> tel: 8-616 77613; >> Don't worry, be happy and make things better ;) >> http://galvosukykla.lt >> >> -- >> 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 [email protected] <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > > -- 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 [email protected]. For more options, visit https://groups.google.com/d/optout.

