Home:ALL Converter>Django Simple History Delete all History on Model Delete

Django Simple History Delete all History on Model Delete

Ask Time:2016-06-06T09:24:27         Author:Nick

Json Formatter

Using django simple history, is there a way to delete all the history associated with an object if the object itself is deleted? For example, if I have a User model:

User.objects.filter(id=to_delete_id).delete()

That query will delete that User, but it doesn't erase all the history, which I would like to save on data costs. Is there a way to automatically delete all of that specific user's history on delete, or do I have to do this:

User.objects.filter(id=to_delete_id).delete()
User.history.filter(id=to_delete_id).delete()

Thanks.

Author:Nick,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/37648419/django-simple-history-delete-all-history-on-model-delete
Nick :

I think I found a solution, let me know if this is bad for some performance reason:\n\nOverride the delete() method on a User:\n\nclass User(...):\n ...\n def delete(self):\n self.history.filter().delete()\n super(User, self).delete()\n",
2016-06-06T02:28:05
yy