Django Signals¶
Use cases¶
Permissions: post_save
--> assign to "Superuser" role
models.py
from django.db.models.signals import pre_save
from django.dispatch import receiver
@receiver(pre_save, sender=Comment)
def do_something_on_save(sender, instance, **kwargs):
# previous value
print(sender.objects.get(id=instance.id))
# new value
print(instance)
Last update:
2023-04-24