
Security News
ESLint Adds Official Support for Linting HTML
ESLint now supports HTML linting with 48 new rules, expanding its language plugin system to cover more of the modern web development stack.
.. image:: https://github.com/makinacorpus/django-safedelete/workflows/Python%20application/badge.svg :target: https://github.com/makinacorpus/django-safedelete/actions?query=workflow%3A%22Python+application%22
.. image:: https://img.shields.io/pypi/dm/django-safedelete.svg :target: https://pypi.python.org/pypi/django-safedelete
.. image:: https://coveralls.io/repos/makinacorpus/django-safedelete/badge.png :target: https://coveralls.io/r/makinacorpus/django-safedelete
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 :
.. code-block:: python
# 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()
Current branch (1.3.x) is tested with :
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
:
.. code-block:: python
INSTALLED_APPS = [
'safedelete',
[...]
]
The application doesn't have any special requirement.
In the main django settings you can activate the boolean variable SAFE_DELETE_INTERPRET_UNDELETED_OBJECTS_AS_CREATED
.
If you do this the update_or_create()
function from django's standard manager class will return True
for
the created
variable if the object was soft-deleted and is now "revived".
By default, the field that indicates a database entry is soft-deleted is deleted
, however, you can override the field name
using the SAFE_DELETE_FIELD_NAME
setting.
The documentation is available here <http://django-safedelete.readthedocs.org>
_. Generate your own documentation using:
tox -e docs
Please see the LICENSE file.
Please see the AUTHORS file.
.. image:: https://drupal.org/files/imagecache/grid-3/Logo_slogan_300dpi.png :target: http://www.makina-corpus.com
values_list
** Bugfixes **
** Bugfixes **
** Bugfixes **
** Refactoring **
** New **
** Removed **
** Bugfixes **
** Refactoring **
** New **
deleted
is now a datetime.** Refactoring **
to config.py
.** New **
DELETED_VISIBLE_BY_PK
to DELETED_VISIBLE_BY_FIELD
to be able to change the field used.** New **
SOFT_DELETE_CASCADE
policy which perform a SOFT_DELETE on safedelete related objects** New **
NO_DELETE
policy which never soft or hard deletes an instance** Removed **
** Bugfixes **
all_with_deleted
method doesn't lose current queryset on a related manager** New **
** New **
FAQs
Mask your objects instead of deleting them from your database.
We found that django-safedelete demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 8 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint now supports HTML linting with 48 new rules, expanding its language plugin system to cover more of the modern web development stack.
Security News
CISA is discontinuing official RSS support for KEV and cybersecurity alerts, shifting updates to email and social media, disrupting automation workflows.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.