[Django]-Django "Manager isn't accessible via UserProfile instances"

4👍

You already have the UserProfile instance when you done request.user.userprofile,

at this point, you have a Instance of UserProfile. you can’t use the object manager (.objects) from that.

you only need

changepass = request.user.userprofile

Another way to get the userprofile object, is doing

UserProfile.objects.get(user=request.user)

3👍

You can’t access a Manager through a Model instance. In your case, request.user is an instance of the User class.

To access the manager, you need to use the UserProfile class directly.

Although, for what you’re trying to accomplish, it’s much easier to transverse the database through the request’s user object:

changepass = request.user.userprofile

2👍

Try using just

changepass = UserProfile.objects.get(user=request.user)

Leave a comment