Django Signals Example


Django tip:

If you need a decoupled application to get notified when actions occur elsewhere in the framework, you can use a Django signal.

For example:

from django.db.models.signals import post_save
from django.dispatch import receiver


@receiver(post_save, sender=Book)
def last_reading_from_reading_list(sender, instance, **kwargs):
    ReadingList.objects.get(id=instance.reading_list.id).save(
        update_fields=["last_reading_at"]
    )