Built-in Signals
Django provides a set of built-in signals that let user code get notified by Django itself of certain actions. These include some useful notifications:
django.db.models.signals.pre_save
&django.db.models.signals.post_save
Sent before or after a model’s
save()
method is called.django.db.models.signals.pre_delete
&django.db.models.signals.post_delete
Sent before or after a model’s
delete()
method or queryset’sdelete()
method is called.django.db.models.signals.m2m_changed
Sent when a
ManyToManyField
on a model is changed.django.core.signals.request_started
&django.core.signals.request_finished
Sent when Django starts or finishes an HTTP request.
See the built-in signal documentation for a complete list, and a complete explanation of each signal.
Listen to Signals
To receive a signal, register a receiver function using the Signal.connect()
method. The receiver function is called when the signal is sent:
|
|