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

django post_save signal and ManyToManyField (and Django Admin)

I have a problem with a post_save function. The function is correctly triggered but the instance doesn't contains the value insereted. I checked the function using ipdb and there is nothing wrong. Simply the ManyToManyField is empty. The…
Karim N Gorjux
  • 2,880
  • 22
  • 29
4
votes
2 answers

Sending emails when a user is activated in the Django admin

I'm about to create a site that has monitored registration in that only certain people are allowed to register. Undoubtedly some misfits will register despite any writing I put above the registration form so we're going with moderation. Upon…
Oli
  • 235,628
  • 64
  • 220
  • 299
4
votes
2 answers

invoke function just after user login in django

I was looking for a way to invoke a function (do_something) just after user logged-in. def do_something(request): # do blah-blah return data One way of doing is that I can check the referrer page using META['HTTP_REFERER'] if it comes…
Vaibhav Kumar
  • 518
  • 3
  • 12
4
votes
1 answer

run some python function whenever a model is created or updated in django?

I want to run some code after my model is saved. Three places to do this will be 1) override save method: def save(self, *args, **kwargs): super(Blog, self).save(*args, **kwargs) do_something() 2) use post_save signal: def…
brain storm
  • 30,124
  • 69
  • 225
  • 393
4
votes
4 answers

Django delete without calling signals

I use signals for things that should always be done when an object is deleted, saved, updated, etc. However, there are times when I don't want to call my save signals, so I use Model.objects.filter(id=instance.id).update(field=value) instead of the…
tzenderman
  • 2,523
  • 3
  • 21
  • 24
4
votes
4 answers

Best way to add common date_added, date_modified to many models in Django

I am adding date_added and date_modified fields to a bunch of common models in my current project. I am subclassing models.Model and adding the appropriate fields, but I want to add automated save behavior (i.e: evey time anyone calls…
Deano
  • 1,136
  • 10
  • 19
4
votes
1 answer

Many to many field not shown in object while using signals to detect save operation in django

This is a follow up question to : Cant get post_save to work in Django My models are : class Car(models.Model): name = models.CharField(max_length=50) ... some other attributes of Car ... class Person(models.Model): car =…
Indradhanush Gupta
  • 4,067
  • 10
  • 44
  • 60
4
votes
1 answer

May an instance be committed if an exception occurs in the post_save handler?

I have a post_save handler that inserts additional records into the database referring to the instance that was just created or updated. However, an error (perhaps a constraint violation) may occur when inserting the additional records. If an…
Jeremy
  • 1
  • 85
  • 340
  • 366
4
votes
1 answer

django m2m_changed signal with custom through model

I am trying to use the m2m_changed signal to trigger some actions in my application . However, the printout of signaltest() indicates that I am only signalled on pre_clear and post_clear actions. My models.py looks like this: class…
m000
  • 5,932
  • 3
  • 31
  • 28
4
votes
1 answer

Migrating django.dispatch.dispatcher from Django 0.96 to 1.0.2

How does one perform the following (Django 0.96) dispatcher hooks in Django 1.0? import django.dispatch.dispatcher def log_exception(*args, **kwds): logging.exception('Exception in request:') # Log errors. django.dispatch.dispatcher.connect( …
Brian M. Hunt
  • 81,008
  • 74
  • 230
  • 343
4
votes
1 answer

Current user in pre_delete signal in django

Is it possible to get a signed in django user (that calls model's delete method) in a callback connected to pre_delete signal?
Pawel Markowski
  • 1,186
  • 3
  • 12
  • 21
4
votes
1 answer

django post_save call from within sending Model?

I have a pretty simple model that works: class Badge(models.Model): name = models.CharField(max_length=16, help_text="Name for Badge") category = models.ForeignKey(BadgeCategory, help_text="Category for badge") description =…
jduncan
  • 677
  • 2
  • 12
  • 22
4
votes
3 answers

django how do i send a post_save signal when updating a user?

having read the docs, https://docs.djangoproject.com/en/dev/topics/signals/ i have created this in my signals.py file: from django.db.models.signals import post_save from django.dispatch import receiver from models import User from models import…
bharal
  • 15,461
  • 36
  • 117
  • 195
3
votes
2 answers

django signals. how to create a unique dispatch id?

sometimes signals in django are triggered twice. In the docs it says that a good way to create a (unique) dispatch_uid is either the path or name of the module[1] or the id of any hashable object[2]. Today I tried this: import…
xpanta
  • 8,124
  • 15
  • 60
  • 104
3
votes
2 answers

Django exclude model from sending signals

I wanted to track my models and their CRUD operations through handling post_save, delete and init signals, and then save entry to the Database about this operation handled. def handle_model_saved(sender, **kwargs): """Trap the signal and do…
Feanor
  • 3,568
  • 5
  • 29
  • 49