Provide Support for Logical Deletes on Models and in the Django Admin
This is a small and simple app that Patrick Altman wrote to get some reuse out of something he did in nearly every project and every model he created. 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 to this rule, however, that are useful.
- In the admin it is nice to see everything with an indicator of whether or not it has been deleted, with the ability to filter down to just active records, (or deleted for that matter).
- It is a valid request when an item is fetched by its primary key value, that the object should return, even if it is marked as deleted.
On May 25, 2015, Patrick donated
django-logicaldelete to Pinax and as part of
pinax-models was born and the code incorporated into that
package. It remains just a Django app and can be quite independently of other
To learn more about Pinax, see http://pinaxproject.com/
pip install django-models
Using the app is pretty simple:
pinax.modelsto your INSTALLED_APPS
- Inherit from
pinax.models.LogicalDeleteModelfor all models that you wish to share in this functionality.
- Create and/or Register admins for each of these models using
Logical deletes are handled by date stamping a
date_removed column. In
date_modified columns will be populated as a
Backwards Incompatible Changes
- Renamed to
pinax-modelsand base model renamed to
- LogicalDeleteManager moved from