Hay,我正在使用django的contrib.auth系统,它显然允许我创建User对象,我也使用了profile模块。这是通过AUTH_PROFILE_MODULE加载的。
使用信号在创建用户时如何创建新的UserProfile对象?
由于
答案 0 :(得分:3)
我在Account中创建了一个新条目,作为我的UserProfile:
from django.db.models.signals import post_save
from django.contrib.auth.models import User
from wizard.models import Account
def make_account(sender, **kwargs):
if 'created' not in kwargs or not kwargs['created']:
return
user = kwargs["instance"]
account = Account(user=user, name="Account for %s" % user.username)
account.save()
post_save.connect(make_account, sender=User, weak=False)