Error:
request.user.userprofile_set
AttributeError: 'User' object has no attribute 'get_profile'
Fix:
a)
Remove
AUTH_PROFILE_MODULE = "core.userprofile"
from settings.py
b)
Change "ForeignKey" to "OneToOneField"
Then add keyword arg related_name='profile'
class UserProfile(models.Model):
user = models.ForeignKey(User, unique=True)
To
class UserProfile(models.Model):
user = models.OneToOneField(User, unique=True, related_name='profile')
c)
Change
request.user.userprofile_set.all()
To
request.user.profile
request.user.userprofile_set
AttributeError: 'User' object has no attribute 'get_profile'
Fix:
a)
Remove
AUTH_PROFILE_MODULE = "core.userprofile"
from settings.py
b)
Change "ForeignKey" to "OneToOneField"
Then add keyword arg related_name='profile'
class UserProfile(models.Model):
user = models.ForeignKey(User, unique=True)
To
class UserProfile(models.Model):
user = models.OneToOneField(User, unique=True, related_name='profile')
c)
Change
request.user.userprofile_set.all()
To
request.user.profile
No comments:
Post a Comment