Skip to main content

Mask your objects instead of deleting them from your database.

Project description

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

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()

Installation

The application doesn’t have any special requirement.

It have been tested with Django 1.3, 1.4 and 1.5, using python 2.6 and 2.7. It is also compatible with python 3, using Django 1.5.

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

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

django-safedelete-0.1.2.tar.gz (6.2 kB view details)

Uploaded Source

File details

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

File metadata

File hashes

Hashes for django-safedelete-0.1.2.tar.gz
Algorithm Hash digest
SHA256 4f84faeaab951973e60a8e5b4bcbceaf2ad39299fc8aeca8fa4283f5209cdcb8
MD5 1afd2e25d9e79be1bcc29ea0be7c588d
BLAKE2b-256 d2e2920761086dc69ffa327d667f2f8f364d746f3ee4cff5d39e8bea14a67068

See more details on using hashes here.

Supported by

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