Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

Mask your objects instead of deleting them from your database.

Project Description

Django safedelete

What is it ?

For various reasons, you may want to avoid deleting objects from your database.

This Django application provides an abstract model, that allows you to transparently retrieve or delete your objects, without having them deleted from your database.

You can choose what happens when you delete an object :
  • it can be masked from your database (soft delete, the default behavior)
  • it can be normally deleted (hard delete)
  • it can be hard-deleted, but if its deletion would delete other objects, it will only be masked
  • it can be never deleted or masked from your database (no delete, use with caution)

Example

# imports
from safedelete.models import SafeDeleteModel
from safedelete.models import HARD_DELETE_NOCASCADE

# Models

# We create a new model, with the given policy : Objects will be hard-deleted, or soft deleted if other objects would have been deleted too.
class Article(SafeDeleteModel):
    _safedelete_policy = HARD_DELETE_NOCASCADE

    name = models.CharField(max_length=100)

class Order(SafeDeleteModel):
    _safedelete_policy = HARD_DELETE_NOCASCADE

    name = models.CharField(max_length=100)
    articles = models.ManyToManyField(Article)


# Example of use

>>> article1 = Article(name='article1')
>>> article1.save()

>>> article2 = Article(name='article2')
>>> article2.save()

>>> order = Order(name='order')
>>> order.save()
>>> order.articles.add(article1)

# This article will be masked, but not deleted from the database as it is still referenced in an order.
>>> article1.delete()

# This article will be deleted from the database.
>>> article2.delete()

Compatibilities

  • Branch 0.2.x is compatible with django >= 1.2
  • Branch 0.3.x is compatible with django >= 1.4
  • Branch 0.4.x is compatible with django >= 1.8

Current branch (0.4.x) has been tested with :

  • Django 1.8 using python 2.7 and python 3.3 to 3.4.
  • Django 1.9 using python 2.7 and python 3.4 to 3.5.
  • Django 1.10 using python 2.7 and python 3.4 to 3.5.

Installation

Installing from pypi (using pip).

pip install django-safedelete

Installing from github.

pip install -e git://github.com/makinacorpus/django-safedelete.git#egg=django-safedelete

Add safedelete in your INSTALLED_APPS:

INSTALLED_APPS = [
    'safedelete',
    [...]
]

The application doesn’t have any special requirement.

Documentation

The documentation is available here. Generate your own documentation using:

tox -e docs

Licensing

Please see the LICENSE file.

Contacts

Please see the AUTHORS file.

CHANGELOG

0.4.3

** Bugfixes **

  • Set SafeDeleteMixin as abstract

0.4.2

** Bugfixes **

  • iterator() now filter the deleted objects correctly.
  • Fix prefetch_related() with all()
  • Fix: “Cannot filter a query once a slice has been taken” error.

** Refactoring **

  • Resolve Django 1.9+ allow_tags deprecation warning
  • Fix docstring typo in SafeDeleteManager, SOFT_DELETE should be DELETED_INVISIBLE

0.4.1

** New **

  • Filtering on the deleted field is done on evaluation.
  • Added specific managers: all_objects and deleted_objects.
  • Added ‘force_policy’ feature to SafeDeleteQuerySet.

** Removed **

** Bugfixes **

  • Fixed abstract intermediate models not working with SOFT_DELETE_CASCADE

** Refactoring **

  • Renamed SafeDeleteMixin to SafeDeleteModel to better reflect the intended behavior. Using SafeDeleteMixin now throws a DeprecationWarning.
  • Moved SafeDeleteQueryset

0.4.0

** New **

  • deleted is now a datetime.

** Refactoring **

  • Globals (HARD_DELETE, SOFT_DELETE, …) have been moved to config.py.
  • Removed support for Django 1.4 to 1.7. You should use the 0.3.x branch if you need to use safedelete in Django <= 1.7.
  • Remove factories to use mixins instead.

0.3.5

** New **

  • Change DELETED_VISIBLE_BY_PK to DELETED_VISIBLE_BY_FIELD to be able to change the field used.

0.3.4

** New **

  • Add a SOFT_DELETE_CASCADE policy which perform a SOFT_DELETE on safedelete related objects
  • Django 1.8 compatibility

0.3.2

  • Prevent migration errors on django 1.8 by declaring the SafeDeleteManager (internal class in managers) as global

0.3.1

  • Fix issue with release on pypi not being the good one

0.3.0

** New **

  • Add a NO_DELETE policy which never soft or hard deletes an instance
  • Django 1.8 compatibility

** Removed **

  • Support of Django 1.2 and Django 1.3 has been removed

** Bugfixes **

  • all_with_deleted method doesn’t lose current queryset on a related manager
  • uniqueness is now checked against soft deleted instances too
  • prefetch_related() now works with SafedeleteQuerySet
  • Fix the undelete action in the administration for active objects.

0.2.1 (2014-12-15)

** New **

  • Extends Django compatibility to Django 1.2

0.2.0 (2014-12-09)

** New **

  • Django compatilibty 1.3 => 1.7
  • Add administration utilities
Release History

Release History

This version
History Node

0.4.3

History Node

0.4.2

History Node

0.4.1

History Node

0.4.0

History Node

0.3.5

History Node

0.3.4

History Node

0.3.3

History Node

0.3.2

History Node

0.3.1

History Node

0.3.0

History Node

0.2.1

History Node

0.2.0

History Node

0.1.3

History Node

0.1.2

History Node

0.1.1

History Node

0.1

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
django-safedelete-0.4.3.tar.gz (19.7 kB) Copy SHA256 Checksum SHA256 Source Sep 18, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting