Skip to content

Instantly share code, notes, and snippets.

@WazedKhan
Last active November 6, 2023 14:48
Show Gist options
  • Select an option

  • Save WazedKhan/c690bf4572feb4964734e72022dfe4c7 to your computer and use it in GitHub Desktop.

Select an option

Save WazedKhan/c690bf4572feb4964734e72022dfe4c7 to your computer and use it in GitHub Desktop.
Passing Arguments for Pre-Save and Post-Save Events
# Pass extra argument from pre save to post save
from django.db.models.signals import pre_save, post_save
from django.dispatch import receiver
@receiver(pre_save, sender=YourModel)
def pre_save_handler(sender, instance, **kwargs):
# You can access the instance being saved and other arguments
your_argument = instance.some_value
# Perform actions with your_argument
@receiver(post_save, sender=YourModel)
def post_save_handler(sender, instance, created, **kwargs):
# You can access the instance, created flag, and other arguments
your_argument = instance.some_value
# Perform actions with your_argument
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment