That explains it then. I put in a test comment before creating the first
user account.

I'll just purge that account. Thanks!
On Jan 6, 2013 3:28 PM, "Massimo Di Pierro" <massimo.dipie...@gmail.com>
wrote:

> {{=comment.author.first_name}}
>
> is correct but:
> 1) fails if some records have comment.author == None
> 2) makes a nested recursive select
>
> You can address 1 with:
> {{=comment.author.first_name if comment.author else 'Unknown'}}
>
> You can address both with a join:
>
>  comments = db(db.comment.author==db.auth_user.id).select()
>
>
> <div id="comments">
>     {{for row in comments:}}
>     <p>{{=row.comment.body}}</p>
>     <p>By {{=row.auth_user.first_name}} on {{=row.comment.postedon}}
>     {{pass}}
> </div>
> <div>{{=post}}</div>
>
> On Sunday, 6 January 2013 16:52:44 UTC-6, HittingSmoke wrote:
>>
>> I'm trying to get my comment page to show the comment author by first and
>> last name. Unfortunately I can't get it to display anything but user ID.
>>
>> My db model:
>>
>> db.define_table('comments',
>>     Field('author', db.auth_user, default=auth.user_id, writeable=False),
>>     Field('postedon', 'date',
>>         default=request.now, update=request.now, writable=False),
>>     Field('body', 'text', required=True))
>>
>>
>> This is my controller:
>>
>> def index():
>>     images = db().select(db.photos.ALL)
>>     comments = db().select(db.comments.ALL)
>>     post = crud.create(db.comments)
>>     return dict(images=images, comments=comments, post=post)
>>
>>
>> And this is the relevant part of my view:
>>
>> <div id="comments">
>>     {{for comment in comments:}}
>>     <p>{{=comment.body}}</p>
>>     <p>By {{=comment.author.first_name}} on {{=comment.postedon}}
>>     {{pass}}
>> </div>
>> <div>{{=post}}</div>
>>
>> When I try to render it I get an error: <type
>> 'exceptions.AttributeError'> 'NoneType' object has no attribute 'first_name'
>>
>> I've tried multiple different ways do write this out and all return the
>> error ticket. If I remove the first_name reference the page renders fine
>> with auth.user_id in the author spot.
>>
>  --
>
>
>
>

-- 



Reply via email to