I have a model in an app named user_profile
like so:
from django.db import models
from django.contrib.auth.models import User
class UserProfile(models.Model):
user = models.OneToOneField(User)
def __unicode__(self):
return self.user.username
and in my settings:
AUTH_PROFILE_MODULE = 'user_profile.UserProfile'
But if I try:
u = UserProfile.objects.get(pk=1)
p = u.get_profile()
I get the following error:
AttributeError: 'UserProfile' object has no attribute 'get_profile'
What am I missing here?
Any help would be much appreciated.
To anyone else that gets this error by following the old documentation, get_profile()
has been depreciated in django 1.7.
Instead you can just access the userprofile from the user as below..
u_p = user.userprofile
where userprofile
is the name of your UserProfile
class
You can also change to use the newer documentation by clicking on the desired version in the bottom right corner
Er, you're trying to get the user profile of a UserProfile. I expect you mean to get a User, then call get_profile()
on that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With