Questions tagged [django-signals]

Django signals allow listeners to be registered for events within the framework. This allows decoupled handling of, for example, model deletions.

Django signals allow listeners to be registered for events within the framework. This allows decoupled handling of, for example, model deletions.

Quote from docs:

Django includes a “signal dispatcher” which helps allow 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. They’re especially useful when many pieces of code may be interested in the same events.

See documentation.

877 questions
11
votes
1 answer

django post_save signal sends outdated inline formsets

Consider the following: class OrderForm(models.Model): title = models.CharField(max_length=100) desc = models.TextField() class OrderFormLine(models.Model): order = models.ForeignKey(OrderForm) lagel =…
h3.
  • 10,688
  • 15
  • 51
  • 54
11
votes
1 answer

Django Signals in celery

I have a task that runs in a Celerybeat instance. When that task is executed, it sometimes modifies a model object, which should fire off a post/pre_save signal, but it doesn't. The signal is not happening. I imagine this is due to Django's signals…
priestc
  • 33,060
  • 24
  • 83
  • 117
11
votes
1 answer

Django: passing variables from pre_save to post_save signals

I use the pre_save and post_save signals to send analytics to Mixpanel. I prefer to keep this separated from my model's save method. Is there a way to save the old values of an instance when the pre_save signal occurs, and then check the new values…
JacobF
  • 2,305
  • 3
  • 24
  • 36
11
votes
4 answers

Possible to change order of Django signals?

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…
Matt Parrilla
  • 3,171
  • 6
  • 35
  • 54
10
votes
6 answers

How can I prevent post_save recursion in Django?

I have some problems when using signal in Django. post_save occurs recursion because of instance.save() inside of function. But strange thing is only one case occurs recursion. Case not occuring recursion. models.py class…
user3595632
  • 5,380
  • 10
  • 55
  • 111
10
votes
1 answer

Redefinition of AppConfig.ready()

Django 1.9. Trying to learn signals. In the documentation for AppConfig.ready() it is said that "Subclasses can override this method to perform initialization tasks such as registering signals."…
Michael
  • 4,273
  • 3
  • 40
  • 69
10
votes
3 answers

Apps aren't loaded yet. with signals

I have an app not ready style error when i use signal. I think this is due to the User auth in the profile model , from what i've see using google there is some issue with the user auth. i think that the error is here : class…
Bussiere
  • 500
  • 13
  • 60
  • 119
10
votes
2 answers

RemovedInDjango19Warning: Model doesn't declare an explicit app_label

Have gone through Django 1.9 deprecation warnings app_label but answers couldn't fix my problem, so asking again. I have an app that is added to INSTALLED_APPS in settings. when ever I run manage.py runserver, I get this warning, [trimmed path to…
10
votes
1 answer

Django: UserProfile with Unique Foreign Key in Django Admin

I have extended Django's User Model using a custom user profile called UserExtension. It is related to User through a unique ForeignKey Relationship, which enables me to edit it in the admin in an inline form! I'm using a signal to create a new…
Bernhard Vallant
  • 49,468
  • 20
  • 120
  • 148
9
votes
3 answers

Django objects uniqueness hell with M2M fields

class Badge(SafeDeleteModel): owner = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True, on_delete=models.PROTECT) restaurants = models.ManyToManyField(Restaurant) …
David Dahan
  • 10,576
  • 11
  • 64
  • 137
9
votes
4 answers

Django: Signal/Method called after "AppConfig.ready()"

I have an AppConfig.ready() implementation which depends on the readiness of an other application. Is there a signal or method (which I could implement) which gets called after all application ready() methods have been called? I know that django…
guettli
  • 25,042
  • 81
  • 346
  • 663
9
votes
1 answer

django how to get old value and new value in pre_save fucntion

Imagine I have a model called A, which has a field called name. How can I get previous value and new value in pre_save signal? @receiver(pre_save, sender=A) def signal_product_manage_latest_version_id( sender, instance, update_fields=None,…
Tiancheng Liu
  • 782
  • 2
  • 9
  • 22
9
votes
1 answer

django m2m_changed with custom through model

In Django I do have two models "Author" and "Publication" that are connected with a Many-to-Many-Field, so that I can assign different authors to a publication. Additionally, I have to use a custom through-model "Authorship" to define the correct…
BumbleBee
  • 986
  • 9
  • 19
9
votes
3 answers

Why does Django post_save signal give me pre_save data?

Im trying to connect a "Information" object to many "Customers" (see code below) When one Information object is updated, I want to send email to each Customer that is connected to the Information. However, when I log the sold_to field that the…
schmilblick
  • 1,917
  • 1
  • 18
  • 25
9
votes
2 answers

Signals in Linq to Sql?

Does anyone know of a way to do something similar to Django's signals using LINQ to SQL? I'm trying to record when new rows are inserted and when certain columns are updated, so I really just want pre_save and post_save signals. I can kind of do it…
tghw
  • 25,208
  • 13
  • 70
  • 96