当在django中创建“User”对象时,如何使用信号创建新的“UserProfile”对象?

时间:2011-01-10 12:48:35

标签: django signals profile

Hay,我正在使用django的contrib.auth系统,它显然允许我创建User对象,我也使用了profile模块。这是通过AUTH_PROFILE_MODULE加载的。

使用信号在创建用户时如何创建新的UserProfile对象?

由于

1 个答案:

答案 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)