Sorry, should have been:
db.fuelLogging._before_update.append(fuelLogging_before_update)
I have updated the original answer.
Anthony
On Wednesday, January 16, 2019 at 1:02:13 AM UTC-5, mostwanted wrote:
>
> This is my model code, its basically what you did: I am getting this error
> everytime i try to open the view
> *<type 'exceptions.SyntaxError'> invalid table "fuelLogging" attributes:
> set(['before_update'])*
>
> *MODEL CODE*
> def fuelLogging_before_update(*args, **kwargs):
> db.fuelLogging.compute = lambda r: (db.fuelLogging.ODO_Reading * -1) +
> r.ODO_Reading
>
> db.define_table('fuelLogging',
> Field('Quantity', 'integer', requires=IS_NOT_EMPTY()),
> Field('Rate', 'integer', requires=IS_NOT_EMPTY()),
> Field('Total', compute=lambda r: int(r['Quantity'])*int(r[
> 'Rate'])),
> Field('ODO_Reading', 'integer', requires=IS_NOT_EMPTY()),
> Field('Fuel_Usage', compute=lambda r: int(r['Delta'])/
> int(r['Quantity'])),
> Field('Delta', default=0),
> before_update=fuelLogging_before_update)
>
>
> I guess i am doing something wrong somewhere!
>
> On Monday, January 14, 2019 at 11:37:10 PM UTC+2, Anthony wrote:
>>
>> On Monday, January 14, 2019 at 2:23:32 AM UTC-5, mostwanted wrote:
>>>
>>> I am trying your formula but my Delta field is not getting updated. It
>>> is supposed to change as i enter a different value in ODO_Reading.
>>>
>>
>> Please show your exact code. Note, if you are using .update_record, the
>> Row returned by that method will not contain the updated Delta value, as
>> that value is calculated in the database. To get the updated value, you
>> would need to fetch the record from the database.
>>
>> Anthony
>>
>
--
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.