Tutorial :Django Admin & Model Deletion



Question:

I've got a bunch of classes that inherit from a common base class. This common base class does some cleaning up in its delete method.

class Base(models.Model):      def delete(self):          print "foo"    class Child(Base):      def delete(self):          print "bar"          super(Child, self).delete()  

When I call delete on the Child from the shell I get:

bar  foo  

as expected

When I use the admin, the custom delete functions don't seem to get called. Am I missing something obvious?

Thanks,

Dom

p.s. This is obviously a simplified version of the code I'm using, apologies if it contains typos. Feel free to leave a comment and I'll fix it.


Solution:1

According to this documentation bug report (Document that the admin bulk delete doesn't call Model.delete()), the admin's bulk delete does NOT call the model's delete function. If you're using bulk delete from the admin, this would explain your problem.

From the added documentation on this ticket, the advice is to write a custom bulk delete function that does call the model's delete function.

Further information on this behavior is here. The bulk delete action doesn't call the model's delete() method for the sake of efficiency.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »