0

I have the need to change the function of delete - I need to confirm the object has no FK connections and if it does, to deny the delete request.

In the relevant Django documentation it is suggested that the pre- and post-delete signals be used instead, as these are called during bulk deletion, cf the Model object's delete method, which is not called.

Then I read this answer to a similar question which is suggesting that using the signals then excludes delete() calls via the shell/API/script.

I do not know enough about signals to be able to verify this claim, but I am now in a conundrum - I still need to monitor the deleting of objects and reject any that fail certain criteria - regardless of whether done via Model.delete() or directly via SQL.

What solutions have people used to get around this problem?

FWIW: I have authorizations and authentication under control, this will be a fail safe.

Community
  • 1
  • 1
datakid
  • 2,293
  • 5
  • 23
  • 35
  • As you mention in query. I think you can filter records where FK is None. so that you get only those records that not having any relationship, and then delete all records. – Yogesh dwivedi Geitpl Sep 10 '14 at 08:31
  • @yogesh, unfortunately your answer doesn't address my needs at all, thank you though. if I have m = ModelName.objects.get(id=id) and then m.delete() I need the delete method to respect my needs. If I have ms = ModelName.objects.filter(var=True).delete() I also need it to work. As I noted in my question. – datakid Sep 12 '14 at 04:42

0 Answers0