1👍
✅
I don’t understand why you would do the query like that. The moderator is the user, so there doesn’t seem to be any good reason to go back to the class and query by username; you already have the user.
Your query would not give you the UserProfile in any case. If you want that you just need to follow the relation from User to UserProfile:
profile = post.moderator.userprofile
assuming you have a one-to-one field from UserProfile to User.
Also note AUTH_PROFILE_MODULE has long been removed; and it wouldn’t have done anything in this case anyway, as it was only invoked when you called get_profile
and you weren’t.
Source:stackexchange.com