views:

174

answers:

1

Hi,

I have a model looking like this.

class ProjectMembership(models.Model):
    member = models.ForeignKey(User, related_name='project_membership_member_set')

Edit: In a template I want now to access the last_name of the User model. I thought it should work like the following line, but it does not.

{{ project_membership.member.last_name }}

No error is provided. Just the value is missing. I just want to print out the first and last name of the User object referenced in the variable member. Interestingly

{{ project_membership.member }}

does work. This prints out the “human-readable” representation of the User object.

A: 

If project_membership.member gives you the user, then project_membership.member.last_name should give you that user's last_name.

Are you absolutely sure that the user you're testing for has last_name set? Do you get any output on project_membership.member.username? If you try to access project_membership.member.last_name in your view or through the shell, do you get an error or an empty unicode string?

ozan
OMG. The value is obviously not set in the db. I should not go out and try to code the next day .. haha.. It works now with project_membership.member.last_name.
Tom Tom