Reputation: 41433
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
Upvotes: 1
Views: 265
Reputation: 8570
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)
Upvotes: 3