I first tried to override the delete() method but that doesn’t work for QuerySet’s bulk delete method. It should be related to pre_delete signal but I can’t figure it out. My code is as following:
def _pre_delete_problem(sender, instance, **kwargs):
instance.context.delete()
instance.stat.delete()
But this method seems to be called infinitely and the program runs into a dead loop.
Can someone please help me?
If the class has foreign keys (or related objects) they are deleted by default like a
DELETE CASCADEinsql.You can change the behavior using the
on_deleteargument when defining theForeignKeyin the class, but by default it isCASCADE.You can check the docs here.
Now the
pre_deletesignal works, but it doesn’t call thedelete()method if you are using a bulk delete, since its not deleting in a object by object basis.