Unfortunately, since you’re not actually deleting things at the database level, I don’t know of a way to harness Django’s automatic cascade deletion, and you’ll have to do something manually.

If you still wanted to keep things fairly hidden and within the pattern, you could do something like:

class VeryImportantSomethingDeletionModel(SoftDeletionModel)    class Meta:
abstract = True

def delete(self):
self.modelswithforeignkey_set.delete()
# Add a line like the above for each model with a foreign key to this one that you want to be cascade deleted
super(VeryImportantSomethingDeletionModel, self).delete()

And then instead of having your model inherit directly from SoftDeletionModel, it would inherit from its own DeletionModel. The related objects could inherit from SoftDeletionModel or not depending on what you’re going for.

The downside here is that if you add new models with foreign keys to this one that you want to be cascade deleted, you’ll need to remember to update it here, and if you have multiple parent objects that you want to do this for, they’ll each need their own DeletionModel.

Not sure if that’s going to be the right solution for you, but hopefully it’s helpful!

Senior Software Engineer | www.adriennedomingus.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store