Perform action on model delete

08 Oct ยท by Tim Kamanin ยท 1 min read

Surprise, surprise, when you want to perform some actions on model delete, overriding delete() method may be not enough, because when you do bulk delete of models via admin interface it won't touch model's delete() method. The way out of it is using signals:

@receiver(post_delete, sender=Model)
def model_delete(sender, instance, **kwargs):
# Do your on delete action here.

Want to get more ๐Ÿ”ฅ tips like this one?

Subscribe to get notified about new dev tutorials