Last active
November 6, 2023 14:48
-
-
Save WazedKhan/c690bf4572feb4964734e72022dfe4c7 to your computer and use it in GitHub Desktop.
Passing Arguments for Pre-Save and Post-Save Events
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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