Skip to content

Instantly share code, notes, and snippets.

@siumhossain
Created March 27, 2022 08:53
Show Gist options
  • Save siumhossain/09daff98148877d4f47bec559b72ffd0 to your computer and use it in GitHub Desktop.
Save siumhossain/09daff98148877d4f47bec559b72ffd0 to your computer and use it in GitHub Desktop.
Update something in django model and check by signal
from django.db.models.signals import post_save,pre_save
from django.dispatch import receiver
@receiver(pre_save, sender=Product)
def pre_save_user(sender, instance, **kwargs):
if not instance._state.adding:
print ('this is an update')
else:
print ('this is an insert')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment