It is possible to attach signals to `settings.AUTH_USER_MODEL` while taking 
its swappable nature into account.

There might be a better way but that's how I've done it for a reusable 
application of 
mine<https://github.com/charettes/django-tenancy/blob/d6d63af092439a6f66a56ff490efb1f358c02e73/tenancy/signals.py#L8-L25>using
 the `
class_prepared<https://docs.djangoproject.com/en/dev/ref/signals/#django.db.models.signals.class_prepared>`
 
signal.

The technique involves looking up the model cache by app_label and model 
(retrieved from splitting `settings.AUTH_USER_MODEL` by '.') and falling 
back to `class_prepared` if it's not loaded yet. When you have a reference 
to the model, either through `get_model` or `class_prepared` callback, you 
can proceed to signal connecting.

It's a shame `class_prepared`'s sender is the model class and not a str of 
the `app_label.ModelName` form (just like related fields handle deferred 
reference). I wonder if it could be possible to change its behavior while 
maintaining backward compatibility by making a `model_class` an instance of 
a `Signal` subclass instead.

Simon

Le mardi 29 octobre 2013 21:42:32 UTC-4, Val Neekman a écrit :
>
> Folks,
>
> I am to release an app as a reusable app. However, the app makes the use 
> of post_save signals raised by the User model and there is a problem.
>
> With the limitation of a Custom User + Signals in mind, I cannot really 
> call it a "true" reusable app, if it doesn't work for setups that have 
> rolled out their own custom users.
>
> I wonder if anyone has come across the same issue when releasing a "true" 
> reusable app?
>
> Thanks,
>
> Val
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/86c54e4d-ac2e-479c-a24e-c60d1ba61b89%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to