Basic pre_save Signal Example
A snippet showing how to use pre_save signal in Django.
from django.dispatch import receiver
from .models import Article
@receiver(pre_save, sender=Article)
def modify_before_save(sender, instance, **kwargs):
instance.title = instance.title.capitalize()
Explanation:
-
A
pre_savesignal is triggered before anArticleis saved. -
Capitalizes the
Article titlebefore saving.
- Category Signals
- Total Views 323
- Last Modified 17 May, 2026
- Tags #signals #pre_save #models #automation
Previous snippet
Basic post_save Signal Example
Next snippet