Skip to main content

Django safedelete

https://travis-ci.org/makinacorpus/django-safedelete.png https://coveralls.io/repos/makinacorpus/django-safedelete/badge.png

What is it ?

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

This Django application provides a model mixin, 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)

  • 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

# Models

# We create a new mixin, with the given policy : Objects will be hard-deleted, or soft deleted if other objects would have been deleted too.
SafeDeleteMixin = safedelete_mixin_factory(HARD_DELETE_NOCASCADE)

class Article(SafeDeleteMixin):
    name = models.CharField(max_length=100)

class Order(SafeDeleteMixin):
    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

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

  • Django 1.4, using python 2.6 and 2.7.

  • Django 1.5 and 1.6, using python 2.6, 2.7 and 3.x.

  • Django 1.7 using python 2.7 and python 3.x.

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

The application doesn’t have any special requirement.

Documentation

The documentation is available here.

Licensing

Please see the LICENSE file.

Contacts

Please see the AUTHORS file.

https://drupal.org/files/imagecache/grid-3/Logo_slogan_300dpi.png

CHANGELOG

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

Download files

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

Source Distribution

django-safedelete-0.3.0.tar.gz (11.1 kB view details)

Uploaded Source

File details

Details for the file django-safedelete-0.3.0.tar.gz.

File metadata

File hashes

Hashes for django-safedelete-0.3.0.tar.gz
Algorithm Hash digest
SHA256 23e2b84d7f68f34392be2b96d216316d97e87c8d36c5b12af86766ddc5074418
MD5 32d3ad72518ec510a0824d4e92b64d5b
BLAKE2b-256 a60b98a9e0147a1215acf1f824d3142bf5e627d416ea4a6d6a12bab1e514054a

See more details on using hashes here.

Release history Release notifications | RSS feed

1.5.0

2 files

1.4.1

2 files

1.4.0

2 files

1.3.3

2 files

1.3.2

2 files

1.3.1

2 files

1.3.0

2 files

1.2.3

2 files

1.2.2

2 files

1.2.1

2 files

1.2.0

2 files

1.1.2

2 files

1.1.1

2 files

1.1.0

2 files

1.0.0

2 files

0.5.7

2 files

0.5.6

3 files

0.5.5

1 file

0.5.4

1 file

0.5.3

1 file

0.5.2

1 file

0.5.1

1 file

0.5.0

1 file

0.4.5

1 file

0.4.4

1 file

0.4.3

1 file

0.4.2

1 file

0.4.1

1 file

0.4.0

1 file

0.3.5

1 file

0.3.4

1 file

0.3.3

1 file

0.3.2

1 file

0.3.1

1 file

This release

0.3.0 This release

1 file

0.2.1

1 file

0.2.0

1 file

0.1.3

1 file

0.1.2

1 file

0.1.1

1 file

0.1

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page