a base model that provides built in logical delete functionality
Project description
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.
In the admin I like 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).
I still think it is a valid request when an item is fetched for by it’s primary key value, that the object should return, even if it is marked as deleted.
Installing django-logicaldelete
pip install django-logicaldelete
Using django-logicaldelete
Using the app is pretty simple:
add logicaldelete to your INSTALLED_APPS
Inherit from logicaldelete.models.Model for all models that you wish to share in this functionality.
Create and/or Register admins for each of these models using logicaldelete.admin.ModelAdmin
Additional
Logical deletes are handled by date stamping a date_removed column. In addition, a date_created and date_modified columns will be populated as a convenience.
Backwards Incompatible Changes
1.1
Changed everything to all_with_deleted on LogicalDeleteManager
LogicalDeleteManager moved from logicaldelete.models to logicaldelete.managers
Removed deleted and everything querysets from logicaldelete.models.Model
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file django-logicaldelete-1.1b1.dev2.tar.gz
.
File metadata
- Download URL: django-logicaldelete-1.1b1.dev2.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b5b4c81ba39e12e7a5eb86b70e3dd42cf161c69985734774cf3f349c4fc9eb2e |
|
MD5 | 6210f0349ace07a776d2278cf90a02ff |
|
BLAKE2b-256 | d34720cd79dccee4edaf27f70d69433864b4c4d55fe23eaae417ea5b1114b285 |