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.
If
project_membership.membergives you the user, thenproject_membership.member.last_nameshould give you that user’slast_name.Are you absolutely sure that the user you’re testing for has
last_nameset? Do you get any output onproject_membership.member.username? If you try to accessproject_membership.member.last_namein your view or through the shell, do you get an error or an empty unicode string?