I have extended User via AUTH_PROFILE_MODULE to include a ManyToMany field to Projects the user is involved in.
I want to reverse the relationship, and get the Users associated with a given Project.
My users have profiles (I’ve successfully returned them with related_projects = u.profile.projects).
related_users = project.userprofile_set.all() is giving me something – {% for user in related_users %} {{ user }} {% endfor %} yields User Profile for: richlyon. But I can’t get {{ user }} to yield any fields. I’ve tried {{ user.username }}.
Question: am I going about this the wrong way? And if I’m not, how do I get field information out of a reverse relationship on an extended User profile?
Thanks as always for your time.
Your ‘profile’ object is not a
User, nor is it extendingUser(in an object-oriented sense). Rather, it’s a separate model that has aForeignKeyto aUser.User > Profile > Projects
In the code you posted, it looks like you’re expecting a
Userobject to be returned from theproject.userprofile_set.all()query set. However, these are going to be your intermediate profile objects from which you can then access the user.Something like this: