Search code examples
pythondjangodjango-usersdjango-1.5

Django 1.5 custom user model - signals limitation


It's written in the doc that:

Another limitation of custom User models is that you can’t use django.contrib.auth.get_user_model() as the sender or target of a signal handler. Instead, you must register the handler with the resulting User model. See Signals for more information on registering an sending signals.

I guess it means you can do the following:

from django.contrib.auth import get_user_model

User = get_user_model()

@receiver(post_save, sender=User)
def user_saved(sender=None, instance=None, **kwargs):
    # something

Isn't it? I'm just wondering if I understand well (I don't understand why they say it's a "limitation", but whatever, just want to check).


Solution

  • That should work. I think they mean to use the same function as sender

    in doc:

    as the sender or target of a signal handler. Instead, you must register the handler with the resulting User model