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
16
votes
4 answers

django-signals vs triggers?

I read about django signals (http://docs.djangoproject.com/en/dev/topics/signals/), but as far as I understand, signals are never converted into literal SQL triggers (http://en.wikipedia.org/wiki/Database_trigger). If I'm correct that signals and…
Alexander Bird
  • 38,679
  • 42
  • 124
  • 159
16
votes
3 answers

How to execute code on post_migrate signal in Django?

I'm doing some kind of refactoring for my project, where I'm relying on the django django.contrib.auth.models.Permission model. So far I define the permissions for each new user using a post_save signal, so when the user is created, I assign their…
slackmart
  • 4,754
  • 3
  • 25
  • 39
16
votes
3 answers

How do I use Django signals with an abstract model?

I have an abstract model that keeps an on-disk cache. When I delete the model, I need it to delete the cache. I want this to happen for every derived model as well. If I connect the signal specifying the abstract model, this does not propagate to…
Conley Owens
  • 8,691
  • 5
  • 30
  • 43
16
votes
3 answers

Django signals for new entry only

I'm using Django's post_save signal to send emails to users whenever a new article is added to the site. However, users still receive new emails whenever I use save() method for already created articles. How is it possible to receive emails only…
user1115538
15
votes
1 answer

Django m2m_changed signal is never called

I can't understand why my m2m_changed signal is not triggered. Here is the code: models.py class Badge(TimeStampable, Expirable, Deactivable, SafeDeleteModel): _safedelete_policy = HARD_DELETE owner =…
David Dahan
  • 10,576
  • 11
  • 64
  • 137
15
votes
1 answer

Using Pre_delete Signal in django

In my app I want to keep a track of all the questions that are being deleted. And so I have created a class(table) as such in my models file. class Deleted(models.Model): question = models.IntegerField(null=True, blank=True)#id of question being…
The Recruit
  • 803
  • 3
  • 9
  • 18
13
votes
3 answers

how to cancel a delete in django signal

Is there a way to cancel a deletion of record using django pre_delete signal? example: def on_delete(sender,**kwargs): if not : #cancel the deletion # else continue with the…
ginad
  • 1,863
  • 2
  • 27
  • 42
13
votes
5 answers

Django: Before a model is updated, I'd like to "look at" its previous attributes

When an update/create is performed on a Django model (.save()) I would like to be able to "step in" and compare some particular attributes to what they were set to previously (if they previously existed at all). I'm thinking Pre-Save Signals, with…
anonymous coward
  • 12,594
  • 13
  • 55
  • 97
13
votes
1 answer

Django Signals: using update_field as condition

Can someone help me understand the update_field argument for Django signals? According to the docs: update_fields: The set of fields to update explicitly specified in the save() method. None if this argument was not used in the save() call. I'm…
Adam Starrh
  • 6,428
  • 8
  • 50
  • 89
13
votes
2 answers

Creating a profile model with both an InlineAdmin and a post_save signal in Django

I created a 'profile' model (with a 1-to-1 relationship to the User model) as described on Extending the existing user model. The profile model has an optional many-to-one relationship to another model: class Profile(models.Model): user =…
12
votes
4 answers

Django pre_save signal does not work

I tested the "pre_save" signal of Django in the following ways, but cannot catch the signal in either of them. $ from django.db.models.signals import pre_save import logging def my_callback(sender, **kwargs): …
Wei An
  • 1,779
  • 4
  • 13
  • 18
12
votes
5 answers

Django signals - kwargs['update_fields'] is always None on model update via django admin

I have a signal inside my django app where I would like to check if a certain field in my model has been updated, so I can then proceed and do something. My model looks like this... class Product(models.Model): name =…
Kingsley
  • 777
  • 1
  • 12
  • 35
12
votes
1 answer

django - difference between signals and celery

This may be a lame question, but I am really confused with these two. I know signals are used to do some task when something has happened. But what about celery? In the documentation it says: Celery is an asynchronous task queue/job queue based on…
Benjamin Smith Max
  • 2,668
  • 8
  • 33
  • 56
12
votes
2 answers

Django: Signal on queryset.update

Django is sending the pre/post_delete signals if you are using the queryset.delete() method, but shouldn't it then also send pre/post_save on queryset.update()?
Bernhard Vallant
  • 49,468
  • 20
  • 120
  • 148
11
votes
1 answer

How to use django-notification to inform a user when somebody comments on their post

I have been developing in django for sometime now, and have developed a neat website having functionality such as writing blogs, posting questions, sharing content etc. However there is still one thing that is missing and i.e. creating notification…
Sachin
  • 3,672
  • 9
  • 55
  • 96