use db._common_fields.append(auth.signature) in your model file.  Read all 
about it here. Use your browser's search to find 
auth.signature.<http://web2py.com/books/default/chapter/29/06>

Then in your index query use
db.comment.created_by==session.auth.user.id # users must be logged in for 
this to work



On Monday, December 10, 2012 3:00:34 PM UTC-5, sasogeek wrote:
>
> I want to have multiple users using my app and each content they produce 
> will be entitled to their accounts, that way if you make a comment for 
> example, your name will be by the comment and if another user should see 
> the comment, they'll see your name by the comment. if i can do this, i 
> believe i can do it for any other produced content, but here're the code 
> snippets followed by the problem I'm facing...
>
> ### Model ###
>
> db.define_table('comment',
>    Field('content_id', 'reference content'),
>    Field('author'),
>    Field('body', 'text'))
>
> ### Controller ####
>
> def show():
>     content = db.content(request.args(0)) or redirect(URL('index'))
>     db.comment.content_id.default = content.id
>     form = crud.create(db.comment,
>                next=URL(args=content.id))
>     form.custom.widget.author = auth.user.first_name +' '+ 
> auth.user.last_name
>     comments = db(db.comment.content_id==content.id).select()
>     return dict(content=content, comments=comments, form=form)
>
> ### View ###
>
> <div style="position:absolute; margin-top:0px;margin-left:100px; 
> margin-right:100px; background-color:#ccc; width:1000;">
> {{if len(comments):}}
>   <h4>Comments</h4>
>   {{for comment in comments:}}
>       <div>{{=comment.author}}: <i>{{=comment.body}}</i></div>
>   {{pass}}
> {{else:}}
>   <h2>No comments posted yet</h2>
> {{pass}}
> <h2>Post a comment</h2>
> {{=form.custom.begin}}
> <div style='float:left;'>Author:</div> <div style="overflow:hidden; 
> margin-left:78;">{{=form.custom.widget.author}}</div>
> <div style='float:left;'>Comment:</div> <div style="overflow:hidden; 
> margin-left:78;">{{=form.custom.widget.body}}</div>
> <div style='float:left;'></div> <div style="overflow:hidden; 
> margin-left:78;">{{=form.custom.submit}}</div>
> {{=form.custom.end}}
>
> Problem: the comment displays None for the author but the comment itself 
> is posted though. This line of code is in the models too. 
> db.comment.author.writable = False
> That way, the author's name can't be altered and is automatically set to 
> the currently logged in user's name.
>
>
> <https://lh4.googleusercontent.com/-ZL1cDigsSlk/UMY-B6puAFI/AAAAAAAAADM/yww7xymjNHg/s1600/Screenshot+from+2012-12-10+16%3A26%3A48.png>
>
> How do I change the "None" to the name of the Author?
>

-- 



Reply via email to