a base model that provides built in logical delete functionality
This is a small and simple app that I threw together to get some reuse out of something I do in nearly every project and every model I create. It’s too easy for good data to get deleted and it be unrecoverable. It’s also too easy to fix this by overriding the model’s delete() method and just flagging records as deleted and then leveraging Django’s Managers to override default behavior so that logically deleted items are not returned in querysets.
There are two exceptions however, that I have found useful to this rule.
pip install django-logicaldelete
Using the app is pretty simple:
logicaldeleteto your INSTALLED_APPS
logicaldelete.models.Modelfor all models that you wish to share in this functionality.
Logical deletes are handled by date stamping a
date_removed column. In addition, a
date_modified columns will be populated as a convenience.