1

Hay, I'm using django's contrib.auth system which obviously allows me to create User objects, I'm also using the profile module. This is loaded through AUTH_PROFILE_MODULE.

Using signals how would i got about create a new UserProfile object when a User is created?

Thanks

dotty
  • 40,405
  • 66
  • 150
  • 195

1 Answers1

3

I'm creating a new entry in Account which acts as my 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)
PhoebeB
  • 8,434
  • 8
  • 57
  • 76