A list of all the signals that Django sends. All built-in signals are sent
using the send() method.
See also
See the documentation on the signal dispatcher for information regarding how to register for and receive signals.
The authentication framework sends signals when a user is logged in / out.
The django.db.models.signals module defines a set of signals sent by the
model system.
Warning
Many of these signals are sent by various model methods like
__init__() or save() that you can
override in your own code.
If you override these methods on your model, you must call the parent class’ methods for these signals to be sent.
Note also that Django stores signal handlers as weak references by default,
so if your handler is a local function, it may be garbage collected. To
prevent this, pass weak=False when you call the signal’s connect().
Note
Model signals sender model can be lazily referenced when connecting a
receiver by specifying its full application label. For example, an
Question model defined in the polls application could be referenced
as 'polls.Question'. This sort of reference can be quite handy when
dealing with circular import dependencies and swappable models.
pre_init¶django.db.models.signals.pre_init¶Whenever you instantiate a Django model, this signal is sent at the beginning
of the model’s __init__() method.
Arguments sent with this signal:
senderargs__init__().kwargs__init__().For example, the tutorial has this line:
q = Question(question_text="What's new?", pub_date=timezone.now())
The arguments sent to a pre_init handler would be:
| Argument | Value |
|---|---|
sender |
Question (the class itself) |
args |
[] (an empty list because there were no positional
arguments passed to __init__()) |
kwargs |
{'question_text': "What's new?",
'pub_date': datetime.datetime(2012, 2, 26, 13, 0, 0, 775217, tzinfo=<UTC>)} |
post_init¶django.db.models.signals.post_init¶Like pre_init, but this one is sent when the __init__() method finishes.
Arguments sent with this signal:
senderinstanceThe actual instance of the model that’s just been created.
Note
instance._state isn’t set before sending the post_init signal,
so _state attributes always have their default values. For example,
_state.db is None and cannot be used to check an instance
database.
Warning
For performance reasons, you shouldn’t perform queries in receivers of
pre_init or post_init signals because they would be executed for
each instance returned during queryset iteration.
pre_save¶django.db.models.signals.pre_save¶This is sent at the beginning of a model’s save()
method.
Arguments sent with this signal:
senderinstancerawTrue if the model is saved exactly as presented
(i.e. when loading a fixture). One should not query/modify other
records in the database as the database might not be in a
consistent state yet.usingupdate_fieldsModel.save(), or None
if update_fields wasn’t passed to save().post_save¶django.db.models.signals.post_save¶Like pre_save, but sent at the end of the
save() method.
Arguments sent with this signal:
senderinstancecreatedTrue if a new record was created.rawTrue if the model is saved exactly as presented
(i.e. when loading a fixture). One should not query/modify other
records in the database as the database might not be in a
consistent state yet.usingupdate_fieldsModel.save(), or None
if update_fields wasn’t passed to save().pre_delete¶django.db.models.signals.pre_delete¶Sent at the beginning of a model’s delete()
method and a queryset’s delete() method.
Arguments sent with this signal:
senderinstanceusingpost_delete¶django.db.models.signals.post_delete¶Like pre_delete, but sent at the end of a model’s
delete() method and a queryset’s
delete() method.
Arguments sent with this signal:
senderinstanceThe actual instance being deleted.
Note that the object will no longer be in the database, so be very careful what you do with this instance.
usingm2m_changed¶django.db.models.signals.m2m_changed¶Sent when a ManyToManyField is changed on a model
instance. Strictly speaking, this is not a model signal since it is sent by the
ManyToManyField, but since it complements the
pre_save/post_save and pre_delete/post_delete
when it comes to tracking changes to models, it is included here.
Arguments sent with this signal: