Django safedelete
=================
.. 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://coveralls.io/repos/makinacorpus/django-safedelete/badge.png
:target: https://coveralls.io/r/makinacorpus/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 masked from your database and mask any dependent models. (cascading 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
-------
.. 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()
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
* Branch 0.5.x is compatible with django >= 1.11
* Branch 1.0.x, 1.1.x and 1.2.x are compatible with django >= 2.2
* Branch 1.3.x is compatible with django >= 3.2 and Python >= 3.7
Current branch (1.3.x) is tested with :
* Django 3.2 using python 3.7 to 3.10.
* Django 4.0 using python 3.8 to 3.10.
* Django 4.1 using python 3.8 to 3.10.
* Django 4.2 using python 3.8 to 3.11.
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``:
.. code-block:: python
INSTALLED_APPS = [
'safedelete',
[...]
]
The application doesn't have any special requirement.
Configuration
-------------
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.
Documentation
-------------
The documentation is available `here <http://django-safedelete.readthedocs.org>`_. Generate your own documentation using:
tox -e docs
Licensing
---------
Please see the LICENSE file.
Contacts
--------
Please see the AUTHORS file.
.. image:: https://drupal.org/files/imagecache/grid-3/Logo_slogan_300dpi.png
:target: http://www.makina-corpus.com
=========
CHANGELOG
=========
1.3.2 (2023-04-05)
==================
- Fix undelete count in admin #220
- Fix de translation
- Fix argument type passed to db_for_write #222
- Django 4.2 support #223
- Fix SafeDeleteQueryset.as_manager() now returns SafeDeleteManager
1.3.1 (2022-10-03)
==================
- Fix exclude exception #216
1.3.0 (2022-08-17)
==================
- Add typings #213
- Drop support for Django < 3.2 and Python 3.6
- Add an index for deleted field #153
1.2.3 (2022-08-17)
==================
- Implement NO_DELETE and HARD_DELETE for queries #209
- Soft-delete-cascade raises an exception when trying to delete a object that related object is PROTECT #210
1.2.2 (2022-05-03)
==================
- Fix soft delete cascade for generic relations #207
- Add count return to delete and undelete methods #204
1.2.1 (2022-04-29)
==================
- Fix related_objects for non-safedelete models.
1.2.0 (2022-04-26)
==================
- Adding SafeDeleteCascadeControlModel #197
- Primary key uniqueness not considered in update_or_create #200
1.1.2 (2021-12-16)
==================
- Add django 4.0 and python 3.10 compatibility and tests #191
- Fix highlight_deleted_field translations #183
1.1.1 (2021-11-15)
==================
- Add highlight_deleted_field #177
- Add new safedelete admin filter #175
- Bug: has_unique_fields() returns false for models.UniqueConstraint #179
1.1.0 (2021-09-23)
==================
- Fix attribute error when union queryset of safe delete model with others #152
- SET related objects after deleting #156
- Avoiding recursive call for delete function. #121
- Add SAFE_DELETE_FIELD_NAME setting #164
- Move filter visibility logic to Query to fix subquery in annotations #160
- Add functions to customize the policies delete behavior #167
1.0.0 (2021-02-15)
==================
- Drop support for Django < 2.2
- Fix deprecation warnings for Django 4.0
0.5.7 (2021-01-28)
==================
- Add visibility filter for union operations #145
- Set related fields when soft deleted #144
- has_unique_fields() now takes into account unique_together option #147
- Fix filtering in subqueries #148
0.5.6 (2020-07-20)
==================
- call self.save() instead of super in delete()
0.5.5 (2020-05-14)
==================
- Admin action now warns if some objects weren't undeleted
- Remove some pre-Django 1.11 support
0.5.4 (2019-12-02)
==================
- Django 3.0 compatibility
0.5.3 (2019-12-02)
==================
- Fix "Doing a .get on a queryset adds deleted objects #131"
0.5.2 (2019-08-19)
==================
- Fix performance issue with Django 2.2
- Fix executing soft delete on already soft-deleted items during cascade soft delete
0.5.1 (2018-07-02)
==================
- Fix possible unicode error in admin
0.5.0 (2018-05-29)
==================
- Remove support for Django 1.8 to 1.10 and Python 3.3.
(it should still works for now but isn't tested, use at your own risks).
- Fix update_or_create (#98)
0.4.5 (2018-01-31)
==================
- Fix an issue with Django 1.8 and `values_list`
- Django 2.0 compatibility
0.4.4 (2018-01-09)
==================
** Bugfixes **
- Fix latest and earliest
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
Raw data
{
"_id": null,
"home_page": "https://github.com/makinacorpus/django-safedelete",
"name": "django-safedelete",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "django,delete,safedelete,softdelete",
"author": "Korantin Auguste",
"author_email": "contact@palkeo.com",
"download_url": "https://files.pythonhosted.org/packages/27/c7/f51ad4467b29c717d25bc9351e169e2b5c282ddec9a726c70078fa957033/django-safedelete-1.3.2.tar.gz",
"platform": null,
"description": "Django safedelete\n=================\n\n.. image:: https://github.com/makinacorpus/django-safedelete/workflows/Python%20application/badge.svg\n :target: https://github.com/makinacorpus/django-safedelete/actions?query=workflow%3A%22Python+application%22\n\n.. image:: https://coveralls.io/repos/makinacorpus/django-safedelete/badge.png\n :target: https://coveralls.io/r/makinacorpus/django-safedelete\n\n\nWhat is it ?\n------------\n\nFor various reasons, you may want to avoid deleting objects from your database.\n\nThis Django application provides an abstract model, that allows you to transparently retrieve or delete your objects,\nwithout having them deleted from your database.\n\nYou can choose what happens when you delete an object :\n - it can be masked from your database (soft delete, the default behavior)\n - it can be masked from your database and mask any dependent models. (cascading soft delete)\n - it can be normally deleted (hard delete)\n - it can be hard-deleted, but if its deletion would delete other objects, it will only be masked\n - it can be never deleted or masked from your database (no delete, use with caution)\n\n\nExample\n-------\n\n.. code-block:: python\n\n # imports\n from safedelete.models import SafeDeleteModel\n from safedelete.models import HARD_DELETE_NOCASCADE\n\n # Models\n\n # 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.\n class Article(SafeDeleteModel):\n _safedelete_policy = HARD_DELETE_NOCASCADE\n\n name = models.CharField(max_length=100)\n\n class Order(SafeDeleteModel):\n _safedelete_policy = HARD_DELETE_NOCASCADE\n\n name = models.CharField(max_length=100)\n articles = models.ManyToManyField(Article)\n\n\n # Example of use\n\n >>> article1 = Article(name='article1')\n >>> article1.save()\n\n >>> article2 = Article(name='article2')\n >>> article2.save()\n\n >>> order = Order(name='order')\n >>> order.save()\n >>> order.articles.add(article1)\n\n # This article will be masked, but not deleted from the database as it is still referenced in an order.\n >>> article1.delete()\n\n # This article will be deleted from the database.\n >>> article2.delete()\n\n\nCompatibilities\n---------------\n\n* Branch 0.2.x is compatible with django >= 1.2\n* Branch 0.3.x is compatible with django >= 1.4\n* Branch 0.4.x is compatible with django >= 1.8\n* Branch 0.5.x is compatible with django >= 1.11\n* Branch 1.0.x, 1.1.x and 1.2.x are compatible with django >= 2.2\n* Branch 1.3.x is compatible with django >= 3.2 and Python >= 3.7\n\nCurrent branch (1.3.x) is tested with :\n\n* Django 3.2 using python 3.7 to 3.10.\n* Django 4.0 using python 3.8 to 3.10.\n* Django 4.1 using python 3.8 to 3.10.\n* Django 4.2 using python 3.8 to 3.11.\n\n\nInstallation\n------------\n\nInstalling from pypi (using pip). ::\n\n pip install django-safedelete\n\n\nInstalling from github. ::\n\n pip install -e git://github.com/makinacorpus/django-safedelete.git#egg=django-safedelete\n\nAdd ``safedelete`` in your ``INSTALLED_APPS``:\n\n.. code-block:: python\n\n INSTALLED_APPS = [\n 'safedelete',\n [...]\n ]\n\n\nThe application doesn't have any special requirement.\n\n\nConfiguration\n-------------\n\nIn the main django settings you can activate the boolean variable ``SAFE_DELETE_INTERPRET_UNDELETED_OBJECTS_AS_CREATED``.\nIf you do this the ``update_or_create()`` function from django's standard manager class will return ``True`` for\nthe ``created`` variable if the object was soft-deleted and is now \"revived\".\n\nBy default, the field that indicates a database entry is soft-deleted is ``deleted``, however, you can override the field name\nusing the ``SAFE_DELETE_FIELD_NAME`` setting.\n\nDocumentation\n-------------\n\nThe documentation is available `here <http://django-safedelete.readthedocs.org>`_. Generate your own documentation using:\n\n tox -e docs\n\n\nLicensing\n---------\n\nPlease see the LICENSE file.\n\nContacts\n--------\n\nPlease see the AUTHORS file.\n\n.. image:: https://drupal.org/files/imagecache/grid-3/Logo_slogan_300dpi.png\n :target: http://www.makina-corpus.com\n\n\n=========\nCHANGELOG\n=========\n\n1.3.2 (2023-04-05)\n==================\n\n- Fix undelete count in admin #220\n- Fix de translation\n- Fix argument type passed to db_for_write #222\n- Django 4.2 support #223\n- Fix SafeDeleteQueryset.as_manager() now returns SafeDeleteManager\n\n1.3.1 (2022-10-03)\n==================\n\n- Fix exclude exception #216\n\n1.3.0 (2022-08-17)\n==================\n\n- Add typings #213\n- Drop support for Django < 3.2 and Python 3.6\n- Add an index for deleted field #153\n\n1.2.3 (2022-08-17)\n==================\n\n- Implement NO_DELETE and HARD_DELETE for queries #209\n- Soft-delete-cascade raises an exception when trying to delete a object that related object is PROTECT #210\n\n1.2.2 (2022-05-03)\n==================\n\n- Fix soft delete cascade for generic relations #207\n- Add count return to delete and undelete methods #204\n\n1.2.1 (2022-04-29)\n==================\n\n- Fix related_objects for non-safedelete models.\n\n1.2.0 (2022-04-26)\n==================\n\n- Adding SafeDeleteCascadeControlModel #197\n- Primary key uniqueness not considered in update_or_create #200\n\n1.1.2 (2021-12-16)\n==================\n\n- Add django 4.0 and python 3.10 compatibility and tests #191\n- Fix highlight_deleted_field translations #183 \n\n1.1.1 (2021-11-15)\n==================\n\n- Add highlight_deleted_field #177\n- Add new safedelete admin filter #175\n- Bug: has_unique_fields() returns false for models.UniqueConstraint #179\n\n1.1.0 (2021-09-23)\n==================\n\n- Fix attribute error when union queryset of safe delete model with others #152 \n- SET related objects after deleting #156\n- Avoiding recursive call for delete function. #121\n- Add SAFE_DELETE_FIELD_NAME setting #164\n- Move filter visibility logic to Query to fix subquery in annotations #160\n- Add functions to customize the policies delete behavior #167\n\n\n1.0.0 (2021-02-15)\n==================\n\n- Drop support for Django < 2.2\n- Fix deprecation warnings for Django 4.0\n\n0.5.7 (2021-01-28)\n==================\n\n- Add visibility filter for union operations #145\n- Set related fields when soft deleted #144\n- has_unique_fields() now takes into account unique_together option #147\n- Fix filtering in subqueries #148\n\n0.5.6 (2020-07-20)\n==================\n\n- call self.save() instead of super in delete()\n\n0.5.5 (2020-05-14)\n==================\n\n- Admin action now warns if some objects weren't undeleted\n- Remove some pre-Django 1.11 support\n\n0.5.4 (2019-12-02)\n==================\n\n- Django 3.0 compatibility\n\n0.5.3 (2019-12-02)\n==================\n\n- Fix \"Doing a .get on a queryset adds deleted objects #131\"\n\n0.5.2 (2019-08-19)\n==================\n\n- Fix performance issue with Django 2.2\n- Fix executing soft delete on already soft-deleted items during cascade soft delete\n\n0.5.1 (2018-07-02)\n==================\n\n- Fix possible unicode error in admin\n\n0.5.0 (2018-05-29)\n==================\n\n- Remove support for Django 1.8 to 1.10 and Python 3.3.\n (it should still works for now but isn't tested, use at your own risks).\n- Fix update_or_create (#98)\n\n0.4.5 (2018-01-31)\n==================\n\n- Fix an issue with Django 1.8 and `values_list`\n- Django 2.0 compatibility\n\n\n0.4.4 (2018-01-09)\n==================\n\n** Bugfixes **\n\n- Fix latest and earliest\n\n0.4.3\n=====\n\n** Bugfixes **\n\n- Set SafeDeleteMixin as abstract\n\n\n0.4.2\n=====\n\n** Bugfixes **\n\n- iterator() now filter the deleted objects correctly.\n- Fix prefetch_related() with all()\n- Fix: \"Cannot filter a query once a slice has been taken\" error.\n\n** Refactoring **\n\n- Resolve Django 1.9+ allow_tags deprecation warning\n- Fix docstring typo in SafeDeleteManager, SOFT_DELETE should be DELETED_INVISIBLE\n\n\n0.4.1\n=====\n\n** New **\n\n- Filtering on the deleted field is done on evaluation.\n- Added specific managers: all_objects and deleted_objects.\n- Added 'force_policy' feature to SafeDeleteQuerySet.\n\n** Removed **\n\n-\n\n** Bugfixes **\n\n- Fixed abstract intermediate models not working with SOFT_DELETE_CASCADE\n\n** Refactoring **\n\n- Renamed SafeDeleteMixin to SafeDeleteModel to better reflect the intended behavior. Using SafeDeleteMixin now throws a DeprecationWarning.\n- Moved SafeDeleteQueryset\n\n\n0.4.0\n=====\n\n** New **\n\n- ``deleted`` is now a datetime.\n\n** Refactoring **\n\n- Globals (HARD_DELETE, SOFT_DELETE, ...) have been moved `to config.py`.\n- 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.\n- Remove factories to use mixins instead.\n\n0.3.5\n=====\n\n** New **\n\n- Change ``DELETED_VISIBLE_BY_PK`` to ``DELETED_VISIBLE_BY_FIELD`` to be able to change the field used.\n\n0.3.4\n=====\n\n** New **\n\n- Add a ``SOFT_DELETE_CASCADE`` policy which perform a SOFT_DELETE on safedelete related objects\n- Django 1.8 compatibility\n\n0.3.2\n=====\n\n- Prevent migration errors on django 1.8 by declaring the SafeDeleteManager (internal class in managers) as global\n\n0.3.1\n=====\n\n- Fix issue with release on pypi not being the good one\n\n\n0.3.0\n=====\n\n** New **\n\n- Add a ``NO_DELETE`` policy which never soft or hard deletes an instance\n- Django 1.8 compatibility\n\n** Removed **\n\n- Support of Django 1.2 and Django 1.3 has been removed\n\n** Bugfixes **\n\n- ``all_with_deleted`` method doesn't lose current queryset on a related manager\n- uniqueness is now checked against soft deleted instances too\n- prefetch_related() now works with SafedeleteQuerySet\n- Fix the undelete action in the administration for active objects.\n\n\n0.2.1 (2014-12-15)\n==================\n\n** New **\n\n- Extends Django compatibility to Django 1.2\n\n\n0.2.0 (2014-12-09)\n==================\n\n** New **\n\n- Django compatilibty 1.3 => 1.7\n- Add administration utilities\n",
"bugtrack_url": null,
"license": "BSD",
"summary": "Mask your objects instead of deleting them from your database.",
"version": "1.3.2",
"split_keywords": [
"django",
"delete",
"safedelete",
"softdelete"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "37cfbcf91f10a75e99426f18661f097c3cd6a38ad7e200679a25d7b6444f7fc9",
"md5": "b8c3e8f90f4887dd46ef7a403f161ee5",
"sha256": "82a97f2fe47654b202b0a7e0e46168292a1e28b5300b8d3cabb5eafa9ee2bda7"
},
"downloads": -1,
"filename": "django_safedelete-1.3.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b8c3e8f90f4887dd46ef7a403f161ee5",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 42747,
"upload_time": "2023-04-05T07:18:54",
"upload_time_iso_8601": "2023-04-05T07:18:54.013599Z",
"url": "https://files.pythonhosted.org/packages/37/cf/bcf91f10a75e99426f18661f097c3cd6a38ad7e200679a25d7b6444f7fc9/django_safedelete-1.3.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "27c7f51ad4467b29c717d25bc9351e169e2b5c282ddec9a726c70078fa957033",
"md5": "d685a9507012ca9cf35ef49bc0fc1886",
"sha256": "27ce5f92d7f4c6adab67c085420aa8c2a8e6751a7fb4a1c0afa70547ddeb2d7d"
},
"downloads": -1,
"filename": "django-safedelete-1.3.2.tar.gz",
"has_sig": false,
"md5_digest": "d685a9507012ca9cf35ef49bc0fc1886",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 31679,
"upload_time": "2023-04-05T07:18:56",
"upload_time_iso_8601": "2023-04-05T07:18:56.697759Z",
"url": "https://files.pythonhosted.org/packages/27/c7/f51ad4467b29c717d25bc9351e169e2b5c282ddec9a726c70078fa957033/django-safedelete-1.3.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-04-05 07:18:56",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "makinacorpus",
"github_project": "django-safedelete",
"travis_ci": false,
"coveralls": true,
"github_actions": true,
"tox": true,
"lcname": "django-safedelete"
}