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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With