25.3 Signals
To create loosely coupled behavior, we can rely on signals and create a signal handler to be activated when a specific signal has been sent. For Django to know of the existence of our signal handler, we can override the ready() method in our AppConfig, loading and registering the signal handler as soon as the website is started.
There are many signals used by Django. Django sends signals before a model is instantiated, after a model is instantiated, before a model is saved, and after a model is saved. There are signals for migrations: the generation of permissions in create_permissions(), which we took control of in Chapter 22: Overriding Django’s Authentication with a Custom User, waits for a post_migrate signal to run, which is ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access