Reputation: 75
I'm using Django 1.5, which allows custom users. I already got the custom users to work on its own. I'd like to add a new model Blah whenever a custom user is created (aka use signals to do this).
currently, I have in signals.py
from group.models import Blah
from django.db.models.signals import post_save
from customuser.models import EmailUser
from django.dispatch import receiver
@receiver(post_save, sender=EmailUser)
def user_saved(sender=None, instance=None, **kwargs):
user = kw["instance"]
print("Request finished!")
if kw["created"]:
blah = Blah(user=user)
blah.save()
in settings.py:
AUTH_USER_MODEL = 'customuser.EmailUser'
As of now, when I'm using Django admin to create a new email user. After I create the EmailUser though, it does not create a new Blah.
I referenced: Django 1.5 custom user model - signals limitation Following this method did not seem to work.
Upvotes: 0
Views: 338
Reputation: 2112
replace user = kw["instance"]
and kw["created"]
with kwargs["instance"]
and kwargs["created"]
and instead of
def user_saved(sender=None, instance=None, **kwargs):
use :
def user_saved(sender, **kwargs):
another thing I do is instead of using the @reciever view wrapper I put the following code at the end of my signals.py file.
post_save.connect(user_saved, sender=EmailUser)
One more thing is to make sure you import the signals file in your urls.py file as well so they actually get loaded.
from yourApp import signals
Upvotes: 1