Alright I think I got it to work although I don't know if it's correct. Basically, I added a user variable to the update_or_insert() function, as follows:
db.tutor.update_or_insert(db.tutor.user==auth.user_id, user = auth.user_id, t_Hourly_Rate = tform.vars.t_Hourly_Rate, t_Image = tform.vars.t_Image, t_Qualifications = tform.vars.t_Qualifications, t_Subjects = tform.vars.t_Subjects, t_Location = tform.vars.t_Location, t_Biography = tform.vars.t_Biography ) My reasoning was that user would be set automatically, since in my db.py file I said db.define_table('tutor', Field('user', 'reference auth.user.id'), ...) But apparently, I need to set that variable. So how does the actual reference work? I'm not sure I get it. Anyway, it seems to be updating the table now so, thanks for the help ;) On Friday, December 7, 2012 11:38:52 PM UTC, Daniele wrote: > > Ok that seems to have done the trick. However, it's creating a new record > every time which means that the logged in user does not refer to the tutor > table. Does the id field have to be the same as auth.user_id? The id field > seems to be generated automatically. In my tutor table I have a line that > says Field('user', 'reference auth.user.id') but the relation does not > seem like it's being made... > > On Friday, December 7, 2012 11:28:06 PM UTC, Anthony wrote: >> >> You can try >> update_or_insert()<http://web2py.com/books/default/chapter/29/06#update_or_insert> >> . >> >> Anthony >> >> On Friday, December 7, 2012 5:54:58 PM UTC-5, Daniele wrote: >>> >>> I am unable to update entries in my database. I think I have an idea of >>> why this may be, but I'm not sure how to go about fixing this. >>> >>> In my controller, I have: >>> >>> tform = SQLFORM.factory( >>> Field('is_tutor', 'boolean'), >>> *[f for f in db.tutor if f.name.startswith('t_')], >>> table_name='tutor') >>> >>> if tform.process().accepted: >>> if tform.vars.is_tutor: >>> if not auth.has_membership('Tutors'): >>> auth.add_membership('Tutors') >>> db(db.tutor.user == auth.user_id).update( >>> t_Hourly_Rate = tform.vars.t_Hourly_Rate, >>> t_Image = tform.vars.t_Image, >>> t_Qualifications = tform.vars.t_Qualifications, >>> t_Subjects = tform.vars.t_Subjects, >>> t_Location = tform.vars.t_Location, >>> t_Biography = tform.vars.t_Biography >>> ) >>> else: >>> if auth.has_membership('Tutors'): >>> auth.del_membership('Tutors') >>> response.flash = T('Profile updated!') >>> elif tform.errors: >>> response.flash = T('There was an error with your submission') >>> >>> >>> However, when I submit the form I am just getting a bunch of 'None' values. >>> I think the problem may be that >>> I'm trying to update db(db.tutor.user == auth.user_id) but if db.tutor.user >>> does not exist, it is not being assigned >>> the value of the currently logged in user (auth.user_id) >>> How can I go about fixing this?? >>> Thanks >>> >>> >>> --