How can I get current row id to update it?
*******************************************

On 13 мар, 04:04, villas <villa...@gmail.com> wrote:
> Do you need a custom form?  How about...
> Use SQLFORM with 'keepvalues'. When user clicks checkbox, submit form
> with jQuery.
> Once that's working experiment with submitting form with ajax.
>
> On Mar 12, 8:15 pm, cyber <vlad.mul...@gmail.com> wrote:
>
>
>
>
>
>
>
> > I have few fields in db like this one:
> >    Field('enter', 'boolean', default=False)
>
> > And I made new page with selection result:
> >    def table():
> >        table=db().select(db.autos.ALL, orderby=~db.autos.dtime)
> >        return dict(table=table)
>
> > Then I wrote code for this new page to represent data from my db:
> >     <form>
> >     {{for nums in table:}}
> >     {{=TR(TD(nums.num),
> >     TD(nums.name),
> >     TD(nums.dtime),
> >     TD(INPUT(_type="checkbox",value=nums.enter)),
> >     TD(nums.enter_d),
> >     TD(INPUT(_type="checkbox",value=nums.idk)),
> >     TD(nums.idk_d),
> >     TD(INPUT(_type="checkbox",value=nums.svh)),
> >     TD(nums.svh_d),
> >     TD(INPUT(_type="checkbox",value=nums.reg)),
> >     TD(nums.reg_d),
> >     TD(INPUT(_type="checkbox",value=nums.out)),
> >     TD(nums.out_d))}}
> >     {{pass}}
> >     </form>
>
> > So, the matter is: how can I change checkboxes state and automaticaly
> > update table in db?
> > Can I add some action when user changes checkboxes state?
> > *************************************************************************** 
> > **************
>
> > On 11 мар, 12:53, cyber <vlad.mul...@gmail.com> wrote:
>
> > > It works perfectly!
> > > I understood your code. Many thanks and respects for you!!!
>
> > > ***
>
> > > Could you give me a piece of advise of how can I use checkboxes to
> > > represent results of db selection?
> > > I have some boolean fields in db and I want users to be able to check/
> > > uncheck checkbox's state. Is it posible?
>
> > > **************************************************************
>
> > > On 10 мар, 17:47, DenesL <denes1...@yahoo.ca> wrote:
>
> > > > 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?

Reply via email to