Thanks for your prompt response. Best Regards,
Thomas Sent from Android On Dec 23, 2011 5:02 PM, "lyn2py" <lyn...@gmail.com> wrote: > Use form.vars.id to get the id of the new record inserted > > More about it here: > http://web2py.com/books/default/chapter/29/7#SQLFORM > (search form.vars.id to get to the paragraph concerned) > > On Dec 23, 3:01 pm, Thomas Dall'Agnese <thomas.dallagn...@gmail.com> > wrote: > > Hi, > > > > Let say I have 2 tables: > > > > db.define_table('post', Field('content')) > > db.define_table('comment', Field('content'), Field('post', 'reference > post)) > > > > When I add a "post" (through a FORM), I would like to automatically add 3 > > comments that refer to that post. > > How can I retrieve the ID of the just inserted post and add the > > comments referring to it? > > > > Currently, I handle to form to add a post like this: > > def add_post(): > > form = SQLFORM(db.post) > > if form.validate(): > > try: > > comments = generateAutoComments() > > except Exception, e: > > response.flash = "Errors generating comments (%s)" % e.message > > else: > > if form.process().accepted: > > # I guess here I would like to add all the comments to > that > > just added post? > > response.flash = 'Post added!' > > return locals()