Package: django-model-signals
Django Model SignalsDjango Model Signals makes it easier to keep business logic in your Django
models by allowing them to become transceivers of their own signals, including
bulk signals.Installationpip install django-model-signalsConfigurationAdd thedjango_model_signalsapp to yourINSTALLED_APPS:INSTALLED_APPS = [
    # ...
    'django_model_signals',
]UsageAdd aModelSignalsMetainner class to your Django model and specify which
signals you want to connect.To enable thepre_bulk_saveandpost_bulk_savesignals, add theModelSignalsManagerto your Django model'sobjectsproperty.To enable thepre_full_clean,post_full_cleanandpost_full_clean_errorsignals, inherit from theFullCleanSignalsMixinin your Django model.To enable thepost_save_errorsignal, inherit from thePostSaveErrorSignalMixinin your Django model.Implement the receiver methods for the connected signals in your Django
model.Examplefromdjango.db.modelsimportModelfromdjango_model_signals.managerimportModelSignalsManagerfromdjango_model_signals.modelsimport(FullCleanSignalsMixin,PostSaveErrorSignalMixin)classMyModel(FullCleanSignalsMixin,PostSaveErrorSignalMixin,Model):@classmethoddefpre_init(cls,**kwargs):passdefpost_init(self,**kwargs):passdefpre_full_clean(self,**kwargs):passdefpost_full_clean(self,**kwargs):passdefpost_full_clean_error(self,**kwargs):raisekwargs['error']defpre_save(self,**kwargs):passdefpost_save(self,**kwargs):passdefpost_save_error(self,**kwargs):raisekwargs['error']defpre_delete(self,**kwargs):passdefpost_delete(self,**kwargs):passdefm2m_changed(self,**kwargs):pass@classmethoddefpre_bulk_save(cls,**kwargs):pass@classmethoddefpost_bulk_save(cls,**kwargs):passobjects=ModelSignalsManager()classModelSignalsMeta:signals=['pre_init','post_init','pre_full_clean','post_full_clean','post_full_clean_error','pre_save','post_save','post_save_error','pre_delete','post_delete','m2m_changed','pre_bulk_save','post_bulk_save']NotesThe following actions are supported for triggering the implemented signals:Creating or loading an model instance from the database will trigger thepre_initandpost_initsignals.CallingModel.full_cleanwill trigger thepre_full_cleanandpost_full_cleansignals.An error duringModel.full_cleanwill trigger thepost_full_clean_errorsignal.CallingModel.savewill trigger thepre_saveandpost_savesignals.An error duringModel.savewill trigger thepost_save_errorsignal.CallingModel.deletewill trigger thepre_deleteandpost_deletesignals.CallingModel.objects.createwill trigger thepre_saveandpost_savesignals.CallingModel.objects.get_or_createwill trigger thepre_saveandpost_savesignals.CallingModel.objects.update_or_createwill trigger thepre_saveandpost_savesignals.CallingModel.objects.bulk_createwill trigger thepre_bulk_saveandpost_bulk_savesignals.CallingModel.objects.bulk_updatewill trigger thepre_bulk_saveandpost_bulk_savesignals.CallingQuerySet.deletewill trigger thepre_deleteandpost_deletesignals.To implement thepre_full_cleanandpost_full_clean,post_full_clean_errorandpost_save_errorssignals, this library
overrides thefull_cleanandsavemethods of Django models and calls the
original method in a backwards compatible way. However, make sure the order
of the classes inherited from is the same as the above example to ensure the
proper method resolution order.Thepost_full_clean_errorandpost_save_errorsignals are not actually
called as signals, but the receiver methods are called directly. This allows
you to suppress, change or re-raise the error.ResourcesDjango:https://www.djangoproject.com/