that's because in the first one you'd like to do in a database what python 
does for the .days conversion (impossible, of course). 
In the second one instead you instruct python to do the calculation and 
pass a "fixed" value to the update, so the db is happy.

On Saturday, October 27, 2012 1:47:07 PM UTC+2, Simon Ashley wrote:
>
> Uncertain why the first fails with the following error:
>
> TypeError: unsupported operand type(s) for -: 'datetime.datetime' and 
> 'Field'
>
> and the second works.
>
> def Update_RData3_dslr():
>     import datetime
>     today = datetime.date.today()
>     db(db.HData.id>0 and db.HData.lrace).update(dslr = (request.now - db.
> HData.lrace).days)
>
>   
>                                                                           
>           
> def Update_RData4_dslr():
>     import datetime
>     today = datetime.date.today()
>     rows = db(db.HData.id>0 and db.HData.lrace).select(db.HData.id, db.
> HData.lrace)
>     for row in rows:
>         dslr = (today - row.lrace).days
>         db(db.HData.id == row.id).update(dslr = dslr)
>
> TIA
>

-- 



Reply via email to