I've got 2 signals being sent at user registration, socialauth_registered and post_save. I'd like for socialauth_registered to precede post_save, as it affects the function that post_save triggers.
Is this possible? (and if it is, how?!)
I'm not sure what exactly is relevant, but I've got:
from django.contrib.auth.models import User
from social_auth.signals import socialauth_registered, pre_update
from django.db.models.signals import post_save
<ALL OF MY MODELS>
def create_user_profile(sender, instance, created, **kwargs):
do some stuff
def create_social_profile(sender, user, response, details, **kwargs):
do other stuff
socialauth_registered.connect(create_social_profile, sender=None)
post_save.connect(create_user_profile, sender=User)
First, to dispel a misconception about signals, they are not executed asynchronously. There is no background thread or worker to execute them. Like most of Django, they are fully "synchronous".
Django includes a “signal dispatcher” which helps decoupled applications get notified when actions occur elsewhere in the framework. In a nutshell, signals allow certain senders to notify a set of receivers that some action has taken place.
There are 3 types of signal. pre_save/post_save: This signal works before/after the method save(). pre_delete/post_delete: This signal works before after delete a model's instance (method delete()) this signal is thrown. pre_init/post_init: This signal is thrown before/after instantiating a model (__init__() method).
The only reason to use signalsOnly use signals to avoid introducing circular dependencies. If you have two apps, and one app wants to trigger behaviour in an app it already knows about, don't use signals. The app should just import the function it needs and call it directly.
No, you cannot change the order that signals are executed.
Signal priority has been proposed, but the core developers have said they will not implement this feature:
https://code.djangoproject.com/ticket/16547
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With