Django注册配置文件字段
|
我正在尝试在django-registration中将位置字段添加到用户的个人资料中。
我添加了以下模型:
# in userprofile/models.py
class Profile(models.Model):
user = models.ForeignKey(User, unique=True)
location = models.CharField(max_length=100, blank=True)
# in settings.py
AUTH_PROFILE_MODULE = \'userprofile.Profile\'
这是可行的-当我手动将数据添加到数据库时,ѭ1可以工作。但是,我在弄清楚如何在通过信号注册期间添加配置文件信息时遇到了麻烦。这是我目前拥有的:
# in backend/default/__init__.py
def register(self, request, **kwargs):
username, email, password = kwargs[\'email\'], kwargs[\'email\'], kwargs[\'password1\']
if Site._meta.installed:
site = Site.objects.get_current()
else:
site = RequestSite(request)
new_user = RegistrationProfile.objects.create_inactive_user(username, email, password, site)
signals.user_registered.send(sender=self.__class__,
user=new_user,
request=request)
# how to add \'location = USA\' to profile via signals here?
return new_user
在上面的__init__.py
函数中,如何使用信号加location=USA
。
没有找到相关结果
已邀请:
1 个回复
厦惫
在__ init __.py中
但这不是做事的好方法,添加应用程序代码