Skip to content

Instantly share code, notes, and snippets.

@pablorecio
pablorecio / models.py
Created August 31, 2011 06:31 — forked from anonymous/models.py
Avoid infinite signals when saving an object instance in Django's pre_save or post_save
from django.db.models.signals import post_save
from django.dispatch import receiver
# models definition here ...
@receiver(post_save, sender=MyModel)
def handler_that_saves_a_mymodel_instance(sender, instance, created, **kwargs):
# without this check the save() below causes infinite post_save signals
if created:
instance.some_field = complex_calculation()