14.2. Utils Signals
>>>
... from django.db.models.signals import pre_save
... from django.dispatch import receiver
... from shop.models import Customer
...
...
... @receiver(pre_save, sender=Customer)
... def my_handler(sender, **kwargs):
... # do something
14.2.1. Model signals
django.db.models.signals.pre_init
django.db.models.signals.post_init
django.db.models.signals.pre_save
django.db.models.signals.post_save
django.db.models.signals.pre_delete
django.db.models.signals.post_delete
14.2.2. M2m relations
django.db.models.signals.m2m_changed
django.db.models.signals.class_prepared
14.2.3. Migrations
django.db.models.signals.pre_migrate
django.db.models.signals.post_migrate
>>>
... from django.apps import AppConfig
... from django.db.models.signals import post_migrate
...
...
... def my_callback(sender, **kwargs):
... # do something
... pass
...
...
... class ShopConfig(AppConfig):
... ...
...
... def ready(self):
... post_migrate.connect(my_callback, sender=self)
14.2.4. Request
django.core.signals.request_started
django.core.signals.request_finished
django.core.signals.got_request_exception
14.2.5. Test
django.test.signals.setting_changed
django.test.signals.template_rendered
14.2.6. Database
django.db.backends.signals.connection_created