Skip to main content

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.

  1. 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).

  2. 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:

  1. add logicaldelete to your INSTALLED_APPS

  2. Inherit from logicaldelete.models.Model for all models that you wish to share in this functionality.

  3. 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

Release files for django-logicaldelete 1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-logicaldelete 1.2
File Size Uploaded
django-logicaldelete-1.2.tar.gz 4.1 kB Details

Release files / django-logicaldelete-1.2.tar.gz

Download URL django-logicaldelete-1.2.tar.gz
Size 4.1 kB
Tags Source
SHA-256 checksum
How to use checksums
284407b94bbefecc52610d382e65cd570ce7bb4c59fb8ebc9b45ec1b0babf07b
BLAKE2b-256 checksum
How to use checksums
8fc87c85eb364db34fd0a7d0e0af5eb796fb0abc345e24e2fb7661575e03d224
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page