Closed DeHess closed 9 months ago
While I'm still of the opinion that some bug is causing the behavior above, I have managed to solve the problem by utilizing a custom form instead of a receiver.
Little did I know that instances can be created / deleted in the form as well, and so I overrode the save() and clean() method of the form to achieve my goal.
My db schema:
And this is my models.py:
I am trying to delete VariableDeviceDescription instances through a m2m receiver like so: (This works when I use normal tabular inlines, but obviously that functionality is not good enough which is why I have chosen this otherwise great package.)
And well it just does not work. Once I press save, I can follow the debugger through this code, it seems to delete the element of the queryset without issue / exception, but then the page reloads and the VariableDeviceDescriptions are unchanged.
I have tried using a custom signal, which is sent out when the clean() method of the Device is called.
I have tried using a pre/post_save receiver on device, where I get the same effect.
I have a theory that the objects get deleted correctly when using these approaches, but get resurrected because their data is held in the inline form when I press save. However, I am terrible with forms / formsets and have no idea where to begin.
I have also tried using a pre/post_init receiver, despite the documentation warning me against making queries in receivers of this type. I had some success there, as the objects actually got deleted. For some reason, “Device” didn’t show up in the app list to the left anymore. Plus I had an error message telling me to “correct the error below” in the formset of the Device, which I could do nothing about. So I abandoned this idea as well.
I appreciate any pointers or ideas as to the solution to this problem.