Demystifying Django signals
Django has a lot of out-of-the-box features, but one feature that is underrated and stands out is Django signals. Django includes a “signal dispatcher” out of the box that helps developers write decoupled logic. A signal dispatcher would notify a set of receivers that some action has taken place. This is useful when we want to execute multiple actions for a single event. By default, Django provides a set of built-in signals that are useful for building common applications, as follows:
- Model signals – These are database action signals that can help developers trigger actions whenever some kind of database operation is about to be performed or is already being performed. Here is the list of default Django signals that are dispatched for certain Django model operation events:
pre_save
andpost_save
– These signals are triggered before and after the model’ssave()
method is called. Please note that these signals are...