After an insert, form.vars.id will have the new record's id. But to avoid another DB access you can make the changes before the record is written using the onvalidation parameter in the accepts.
@auth.requires_login() def new(): def set_name(form): form.vars.name=author return form = SQLFORM(db.autos, fields=['num'], labels={'num':'Number'}, submit_button='GO', formstyle='divs') if form.accepts(request.vars, session, onvalidation=set_name): response.flash = 'Yoh-ho-ho!' elif form.errors: response.flash = 'Bad-bad-bad!' else: response.flash = 'Fill the form' return dict(form=form) On Mar 10, 5:56 am, cyber <vlad.mul...@gmail.com> wrote: > The code in controller: > @auth.requires_login() > def new(): > author=auth.user.username > form = SQLFORM(db.autos, fields=['num'], labels={'num':'Number'}, > submit_button='GO', formstyle='divs') > if form.accepts(request.vars, session): > response.flash = 'It's OK!' > elif form.errors: > response.flash = 'There is an error!' > else: > response.flash = 'Fill the form!' > rows=db(db.autos.id>0).select() > last_row=rows[-1] > last_row.update_record(name=author) > return dict(form=form) > > ******************************* > And the model piece of code is: > import datetime > now=datetime.datetime.today() > db.define_table('autos', > Field('num', length=8), > Field('name'), > Field('dtime', 'datetime', default=now), > Field('enter', 'boolean', default=False), > Field('enter_d'), > Field('idk', 'boolean', default=False), > Field('idk_d'), > Field('svh', 'boolean', default=False), > Field('svh_d'), > Field('reg', 'boolean', default=False), > Field('reg_d'), > Field('out', 'boolean', default=False), > Field('out_d') > ) > > ***************** > And view file is: > {{extend 'layout.html'}} > {{=form}} > > So, I want user to enter only value 'num' in db.autos. > But user_name (for current user) and date_time info have to be updated > automaticly after user presses "GO" button. > Could you check my code? Is it correct? > > On 9 мар, 17:27, DenesL <denes1...@yahoo.ca> wrote: > > > Can you show us your current code?. > > > On Mar 9, 9:03 am, cyber <vlad.mul...@gmail.com> wrote: > > > > Hi > > > > How can I update new (just created) record in the table? > > > Table consists of several fields but in the form page user have to > > > enter only one value for one row. > > > So, I need insert in the current row not only this value but user name > > > and datetime. > > > I can insert first value but I have no idea of how to auto update new > > > row with required values. > > > > Any ideas? > >