Whenever there is a modification in a model, we may need to trigger some actions.
Django provides an elegant way to handle these in the form of signals. The signals are the utilities that allow us to associate events with actions. We can implement these by developing a function that will run when a signal calls it.
List of built-in signals in the models:
Signals |
Description |
django.db.models.pre_init &
django.db.models.post_init |
Sent before or after a models’s _init_() method is called |
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 models’ delete() method or queryset delete() method is called |
django.db.models.signals.m2m_changed |
Sent when a ManyToManyField is changed |
django.core.signals.request_started &
django.core.signals.request_finished |
Sent when an HTTP request is started or finished |