Changelog is correct, section on the book not.
However, here's the patch to the book (also updating the sample function on
field.Method that doesn't run just like it was intended)
On Tuesday, January 1, 2013 10:35:18 PM UTC+1, DenesL wrote:
>
>
> Field.Virtual('total_price', lambda row:
> row.item.unit_price*row.item.quantity)
> works.
>
> Book sample code needs to be fixed. ;)
>
--
diff -r 402d8704306a sources/29-web2py-english/06.markmin
--- a/sources/29-web2py-english/06.markmin lun dic 31 15:30:56 2012 -0600
+++ b/sources/29-web2py-english/06.markmin mar gen 01 22:51:08 2013 +0100
@@ -1649,7 +1649,7 @@
One can define a ``total_price`` virtual field as
``
->>> db.item.total_price = Field.Virtual(lambda row: row.unit_price*row.quantity)
+>>> db.item.total_price = Field.Virtual(lambda row: row.item.unit_price*row.item.quantity)
``:code
i.e. by simply defining a new field ``total_price`` to be a ``Field.Virtual``. The only argument of the constructor is a function that takes a row and returns the computed values.
@@ -1665,7 +1665,7 @@
``
>>> db.item.discounted_total = Field.Method(lambda row, discount=0.0: \
- row.unit_price*row.quantity*(1.0-discount/100))
+ row.item.unit_price*row.item.quantity*(1-discount/100.0))
``:code
In this case ``row.discounted_total`` is not a value but a function. The function takes the same arguments as the function passed to the ``Method`` constructor except for ``row`` which is implicit (think of it as ``self`` for rows objects).