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.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()
我在第user.get_profile.team = team.id
行
/ register处的AttributeError 'instancemethod'对象没有 属性'团队'
如何解决此错误?
答案 0 :(得分:8)
User.get_profile
是一种方法,因此您需要像这样调用它:
user.get_profile().team