Django Signals - post_save()


Django tip:

To impact a different part of your application after the object is saved to the database, you can use a post_save signal.

For example:

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


@receiver(post_save, sender=Order)
def remove_from_inventory(sender, instance, **kwargs):
    inventory_item = Inventory.objects.get(id=instance.inventory_item.id)
    inventory_item.quantity = inventory_item.quantity - instance.quantity

    inventory_item.save()