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 ...

Get Django Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.