I have a model 'B' that is linked to another model 'A' as an inline model, for use in my admin site. Now, whenever I delete an object of model 'B' associated with the corresponding object of model 'A' (via the admin site), I want to perform some more tasks at the backend. I was able to override the save function using a formset and then overriding the save_existing and save_new methods. How do I go about overriding the delete method for the inline admin model?
I was able to get around by overriding the save() method for my model in the models.py itself.
Use pre_delete
or post_delete
signals to execute code before/after model is deleted:
from django.db.models.signals import pre_delete
from django.dispatch import receiver
from myapp.models import MyModel
@receiver(pre_delete, sender=MyModel)
def my_handler(sender, **kwargs):
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With