Package: django-safedelete
Django safedeleteWhat 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. (SOFT_DELETE_CASCADE)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 (HARD_DELETE_NOCASCADE)it can be never deleted or masked from your database (NO_DELETE, use with caution)Example# importsfromsafedelete.modelsimportSafeDeleteModelfromsafedelete.modelsimportHARD_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.classArticle(SafeDeleteModel):_safedelete_policy=HARD_DELETE_NOCASCADEname=models.CharField(max_length=100)classOrder(SafeDeleteModel):_safedelete_policy=HARD_DELETE_NOCASCADEname=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()CompatibilitiesBranch 0.2.x is compatible with django >= 1.2Branch 0.3.x is compatible with django >= 1.4Branch 0.4.x is compatible with django >= 1.8Branch 0.5.x is compatible with django >= 1.11Branch 1.0.x, 1.1.x and 1.2.x are compatible with django >= 2.2Branch 1.3.x is compatible with django >= 3.2 and Python >= 3.7Current 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.InstallationInstalling from pypi (using pip).pip install django-safedeleteInstalling from github.pip install -e git://github.com/makinacorpus/django-safedelete.git#egg=django-safedeleteAddsafedeletein yourINSTALLED_APPS:INSTALLED_APPS=['safedelete',[...]]The application doesn’t have any special requirement.ConfigurationIn the main django settings you can activate the boolean variableSAFE_DELETE_INTERPRET_UNDELETED_OBJECTS_AS_CREATED.
If you do this theupdate_or_create()function from django’s standard manager class will returnTruefor
thecreatedvariable if the object was soft-deleted and is now “revived”.By default, the field that indicates a database entry is soft-deleted isdeleted, however, you can override the field name
using theSAFE_DELETE_FIELD_NAMEsetting.DocumentationThe documentation is availablehere. Generate your own documentation using:tox -e docsLicensingPlease see the LICENSE file.ContactsPlease see the AUTHORS file.CHANGELOG1.3.3 (2023-11-13)Add Hard Delete Action to SafeDeleteAdmin #2361.3.2 (2023-04-05)Fix undelete count in admin #220Fix de translationFix argument type passed to db_for_write #222Django 4.2 support #223Fix SafeDeleteQueryset.as_manager() now returns SafeDeleteManager1.3.1 (2022-10-03)Fix exclude exception #2161.3.0 (2022-08-17)Add typings #213Drop support for Django < 3.2 and Python 3.6Add an index for deleted field #1531.2.3 (2022-08-17)Implement NO_DELETE and HARD_DELETE for queries #209Soft-delete-cascade raises an exception when trying to delete a object that related object is PROTECT #2101.2.2 (2022-05-03)Fix soft delete cascade for generic relations #207Add count return to delete and undelete methods #2041.2.1 (2022-04-29)Fix related_objects for non-safedelete models.1.2.0 (2022-04-26)Adding SafeDeleteCascadeControlModel #197Primary key uniqueness not considered in update_or_create #2001.1.2 (2021-12-16)Add django 4.0 and python 3.10 compatibility and tests #191Fix highlight_deleted_field translations #1831.1.1 (2021-11-15)Add highlight_deleted_field #177Add new safedelete admin filter #175Bug: has_unique_fields() returns false for models.UniqueConstraint #1791.1.0 (2021-09-23)Fix attribute error when union queryset of safe delete model with others #152SET related objects after deleting #156Avoiding recursive call for delete function. #121Add SAFE_DELETE_FIELD_NAME setting #164Move filter visibility logic to Query to fix subquery in annotations #160Add functions to customize the policies delete behavior #1671.0.0 (2021-02-15)Drop support for Django < 2.2Fix deprecation warnings for Django 4.00.5.7 (2021-01-28)Add visibility filter for union operations #145Set related fields when soft deleted #144has_unique_fields() now takes into account unique_together option #147Fix filtering in subqueries #1480.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 undeletedRemove some pre-Django 1.11 support0.5.4 (2019-12-02)Django 3.0 compatibility0.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.2Fix executing soft delete on already soft-deleted items during cascade soft delete0.5.1 (2018-07-02)Fix possible unicode error in admin0.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 andvalues_listDjango 2.0 compatibility0.4.4 (2018-01-09)** Bugfixes **Fix latest and earliest0.4.3** Bugfixes **Set SafeDeleteMixin as abstract0.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 warningFix docstring typo in SafeDeleteManager, SOFT_DELETE should be DELETED_INVISIBLE0.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 SafeDeleteQueryset0.4.0** New **deletedis now a datetime.** Refactoring **Globals (HARD_DELETE, SOFT_DELETE, …) have been movedto 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 **ChangeDELETED_VISIBLE_BY_PKtoDELETED_VISIBLE_BY_FIELDto be able to change the field used.0.3.4** New **Add aSOFT_DELETE_CASCADEpolicy which perform a SOFT_DELETE on safedelete related objectsDjango 1.8 compatibility0.3.2Prevent migration errors on django 1.8 by declaring the SafeDeleteManager (internal class in managers) as global0.3.1Fix issue with release on pypi not being the good one0.3.0** New **Add aNO_DELETEpolicy which never soft or hard deletes an instanceDjango 1.8 compatibility** Removed **Support of Django 1.2 and Django 1.3 has been removed** Bugfixes **all_with_deletedmethod doesn’t lose current queryset on a related manageruniqueness is now checked against soft deleted instances tooprefetch_related() now works with SafedeleteQuerySetFix the undelete action in the administration for active objects.0.2.1 (2014-12-15)** New **Extends Django compatibility to Django 1.20.2.0 (2014-12-09)** New **Django compatilibty 1.3 => 1.7Add administration utilities