Works for me:
>>> db =DAL()
>>> db.define_table('magazzino',
... Field('id_tipo', 'integer',default=0),
... Field('p_p','double', default=0.0),
... Field('pp_tot','double', writable=True, readable=True,
compute=lambda r: r['id_tipo']==0 and r['p_p']*1 or
r['p_p']*r['id_tipo']*-1),
... )
<Table magazzino (id,id_tipo,p_p,pp_tot)>
>>> db.magazzino.insert(id_tipo=1,p_p=10)
1L
>>> print db.magazzino[1]
<Row {'pp_tot': -10.0, 'id_tipo': 1, 'id': 1, 'p_p': 10.0}>
>>> newPp = 100
>>> articolo = db.magazzino[1]
>>> articolo.id_tipo=articolo.id_tipo
>>> articolo.p_p=newPp
>>> articolo.update_record()
<Row {'pp_tot': -10.0, 'id_tipo': 1, 'id': 1, 'p_p': 100}>
what version do you have? Something else is wrong.
By the way your code contains some hidden characters:
articolo = db.magazzino\U+FEFF[request.vars.id] \U+FEFF
Not sure if this is a problem or just a cut-and paste error.
On Saturday, 19 January 2013 11:03:34 UTC-6, palomar wrote:
>
> Other users have the same problem and, sorry but I can't find my solution;
> i tried with readable=true and writable=true, to update all the field
> interested in the compute function, to comment the line in DAL.py, but
> nothing.
>
> I have this table:
> db.define_table('magazzino',
> Field('id_tipo', 'integer',default=0),
> Field('p_p','double', default=0.0),
> Field('pp_tot','double', writable=True, readable=True, compute=lambda
> r: r['id_tipo']==0 and r['p_p']*1 or r['p_p']*r['id_tipo']*-1),
> )
>
> If I edit a row with a FORM the compute field works but if I edit it in a
> function with ajax don't...
>
> def modArtPrice():
> newPp = 100
> articolo = db.magazzino[request.vars.id]
> articolo.id_tipo=articolo.id_tipo
> articolo.p_p=newPp
> articolo.update_record()
>
> what's wrong?
> s.
>
--