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_savesignal is triggered when anInvoiceis 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
Previous snippet
Custom Signal Example
Next snippet