Man.  No luck from what either of you suggested... for some reason no mater 
what I put in the post_id field ends up as 0.  Frustrating.

I guess it doesn't really matter that much through if the best way to about 
is JS.  Come to think of it it would be kind of weird if the whole page 
reloaded every time you posted a comment of facebook.

If you don't mind could you elaborate a little more on doing this in JS 
Massimo?  

Thank you much,

Hunt

On Saturday, August 10, 2013 4:13:34 AM UTC-4, Massimo Di Pierro wrote:
>
> You can but not advisable. You can for example, in controller,
>
> for post in posts:
>    db.post_comment.post_id.default = post.id
>    post.form = SQLFORM(db.post_comment, formname='x%s' % post.id
> ).process()
>
> and in view replace {{=comment_form}} with {{=post.form}}
>
> but you end up generating and processing lots of forms even if only one is 
> used. I would do this with a single form and JS that moves the location of 
> the form and populates a hidden post_id input field.
>
> On Friday, 9 August 2013 19:52:16 UTC-5, hunt graham wrote:
>>
>> 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.


Reply via email to