AUTH_PROFILE_MODULE in django
models.py
class Team(models.Model):
name = models.CharField(max_length=25, unique=True)
def __unicode__(self):
return self.name
class UserProfile(models.Model):
user = models.ForeignKey(User, unique=True)
team = models.ForeignKey(Team, unique=True)
settings.py:
AUTH_PROFILE_MODULE = 'project开发者_StackOverflow中文版.pm.UserProfile'
views.py
if request.method == 'POST':
r = RegisterForm(request.POST)
if r.is_valid():
team = Team(name=request.POST.get('team'))
team.save()
user = User.objects.create_user(username=request.POST.get('email'),
email=request.POST.get('email'),
password=request.POST.get('password'))
user.get_profile.team = team.id
user.save()
I had error on line user.get_profile.team = team.id
AttributeError at /register 'instancemethod' object has no attribute 'team'
How can I fix this error?
User.get_profile
is a method, so you'll need to call it like so:
user.get_profile().team
精彩评论