Hi Anthony,

Thanks for your answer.
I used the form.vars.id way.

And indeed, I had to change my process because the form.process().acceptedwas 
false after doing a 
form.validate().
So I changed the form.validate() with form.process().accepted and delete 
the inserted post if an exception is raised trying to add the comments to 
that post.

def add_post():
   form = SQLFORM(db.post)
   if form.process().accepted:
       try:
           comments = ('comment one', 'comment two', 'comment three')
           for comment in comments:
               db.comment.insert(post=form.vars.id, comment=comment)
       except Exception, e:
           response.flash = "Errors generating comments (%s)" % e.message
           db(db.post.id == form.vars.id).delete()
       else:
           response.flash = 'Post added!'
   return dict(form=form)

Works well, thanks!

Cheers,

Thomas

Reply via email to