gpt4 book ai didi

django - Django 中的 AUTH_PROFILE_MODULE

转载 作者:行者123 更新时间:2023-12-04 11:43:54 24 4
gpt4 key购买 nike

模型.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)

设置.py:
AUTH_PROFILE_MODULE = 'project.pm.UserProfile'

View .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

AttributeError at /register 'instancemethod' object has no attribute 'team'



我该如何解决这个错误?

最佳答案

User.get_profile是一种方法,因此您需要像这样调用它:

user.get_profile().team

关于django - Django 中的 AUTH_PROFILE_MODULE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5843580/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com