Skip to main content

Provide Support for Logical Deletes on Models and in the Django Admin

Project description

https://img.shields.io/travis/pinax/pinax-models.svg https://img.shields.io/coveralls/pinax/pinax-models.svg https://img.shields.io/pypi/dm/pinax-models.svg https://img.shields.io/pypi/v/pinax-models.svg https://img.shields.io/badge/license-MIT-blue.svg

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.

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

  2. 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 that process, pinax-models was born and the code incorporated into that package. It remains just a Django app and can be quite independently of other Pinax apps.

To learn more about Pinax, see http://pinaxproject.com/

Installing pinax-models

pip install django-models

Using pinax-models

Using the app is pretty simple:

  1. add pinax.models to your INSTALLED_APPS

  2. Inherit from pinax.models.LogicalDeleteModel for all models that you wish to share in this functionality.

  3. Create and/or Register admins for each of these models using pinax.models.LogicalDeleteModelAdmin

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

2.0

  • Renamed to pinax-models and base model renamed to LogicalDeleteModel

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pinax-models-2.0.tar.gz (5.1 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page