Hi all, I have a view that pulls from 2 db tables, 'post' and 'post_commet'. In the db, each comment has a post_id to specify which comment. I display them in the view with a nested loop:
{{for post in posts:}} <p><strong>Post: </strong>{{=(post.post_content)}}</p> {{_postId = post.id}} {{comments=db(db.post_comment.post_id == post.id.select()}} {{for c in comments:}} {{print c.comment_text}} <p><strong>Comment: </strong>{{=c.comment_text}}</p> {{pass}} {{=comment_form}} {{pass}} 'comment_form' is a SQLFORM object for the 'post_comment' table. What I'm not sure how to do is automatically set the post_id of the new comment to what it's "parent post" is. If I was doing this manually with <form> and <input> tags, I would set the name attribute of each input tag to the post_id and grab it with request.vars.post_id or something like that. But this way I'd have to implement validation myself and add it to the db manually. Is there a way I can do this using the 'comment_form' SQLFORM? Here is my db code if that matters. Thanks! import datetime # Define posts table db.define_table('post', ##### We need to decide how we'll be handling audio first. ##### ##Field('content', 'upload'), Field('user_id', db.auth_user, default=auth.user_id, readable=True, writable=False, notnull=True), Field('date_posted', 'date', default=datetime.datetime.now(), notnull=True), Field('time_posted', default=datetime.datetime.time(datetime.datetime.now()), notnull=True, writable=False, readable=True), Field('post_content', readable=True, writable=True), Field('up_votes', default=0), Field('down_votes', default=0) ) # Set form reqs for posts db.post.date_posted.writable = False db.post.date_posted.readable = True db.post.up_votes.readable = db.post.down_votes.readable = True db.post.up_votes.writable = db.post.down_votes.writable = False # Define comment table db.define_table('post_comment', Field('user_id', db.auth_user, default=auth.user_id, readable=True, writable=False, notnull=True), Field('post_id', 'reference post', notnull=True), Field('date_posted', 'date', default=datetime.datetime.now()), Field('comment_text'), Field('up_votes'), Field('down_votes') ) # Set form reqs for posts db.post_comment.post_id.writable = db.post_comment.post_id.readable = False db.post_comment.date_posted.writable = False db.post_comment.date_posted.readable = True db.post_comment.up_votes.readable = db.post_comment.down_votes.readable = True db.post_comment.up_votes.writable = db.post_comment.down_votes.writable = False -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.