One-Time Signal Execution

A snippet showing how to make signals execute only once.


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

@receiver(post_save, sender=Invoice)
def process_invoice(sender, instance, created, **kwargs):
    if created and not hasattr(instance, '_processed'):
        instance._processed = True
        print("Invoice processed once")
      
Explanation:
  • A post_save signal is triggered when an Invoice is created.
  • Ensures the invoice is processed only once when created.
  • Category Signals
  • Total Views 766
  • Last Modified 19 May, 2026
  • Tags #signals #once #execution #django
Never miss a story on Django.wiki

Subscribe for fresh tutorials, snippets, and updates.

By subscribing you agree to our Privacy Policy.