#Django signals

3 messages · Page 1 of 1 (latest)

supple quest
#

Hello everyone, I want to write a django signal that fires off whenever a model instance is saved. How can I make the signal available to all apps and models in the project especially when the sender is always going to be a different model?

somber tinsel
#

If you want a signal that fires on model save, you can use the default post_save signal

@receiver(post_save, sender=MyModel)

The nature of the signal is, you can subscribe from any application, whether the sender model is used in the app or not.

#

If you want to subscribe to all save events from all models, you can omit sender=

@receiver(post_save)
def my_func(sender, instance, created, **kwargs)