rajaram_s
rajaram_s

Reputation: 357

Updating web2py auth_user custom fields programmatically

I have a custom field associated with user which stores the score of each user in the auth_user table using auth.settings.extra_fields with both readable=False and writable=False. But I want to update this field programmatically.

I tried the following:

auth.user.score.update(float(balance)-float(cost))

Both balance and cost are well defined variables and I checked returning them individually, which works. I had to try this because I found that it is not possible to access the auth_user table using DAL.

Upvotes: 0

Views: 1484

Answers (1)

Anthony
Anthony

Reputation: 25536

It is indeed possible to access the auth_user table using the DAL. Have you tried:

db(db.auth_user.id == auth.user_id).update(score=float(balance) - float(cost))

Note, auth.user refers to a copy of the user record stored in the session, so changing it does not affect the database record.

Upvotes: 3

Related Questions