0

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.

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

8 Comments

Sorry. I thought it was not possible to access it so since (row = db(db.auth_user.id==auth.user_id) return str(row)) returned nothing for me.
Same is the case with the solution posted by you. Where am I going wrong?
db(db.auth_user.id==auth.user_id) does not return a Row or Rows object -- it is just a DAL Set object (i.e., it defines the query but doesn't select the records from the db). To select the records, you need to do db(db.auth_user.id==auth.user_id).select().
As far as where you're going wrong, it's hard to say without seeing more code.
Thanks a lot Antony. Fixed the issue. The problem was that I was missing on db.commit() after the update and regards selection, it was the mistake that you were pointing out.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.