django-safedelete
Mask your objects instead of deleting them from your database.
What it is and what it does
django-safedelete is a Django application that intercepts model deletion to implement soft-delete behavior—marking objects as deleted in the database without physically removing them. Instead of calling DELETE on the database, it masks records so they remain retrievable for audit, recovery, or compliance purposes while being hidden from normal queries.
You define a deletion policy per model by setting the _safedelete_policy attribute. The package provides five policies: SOFT_DELETE (default, masks the object), SOFT_DELETE_CASCADE (masks the object and dependent models), HARD_DELETE (normal deletion), HARD_DELETE_NOCASCADE (hard-deletes only if no other objects reference it, otherwise soft-deletes), and NO_DELETE (prevents deletion entirely). Models inherit from SafeDeleteModel, and the package handles query filtering, admin integration, and restoration automatically.
Use it for:
- Audit trails: retain deleted records for compliance or historical review without exposing them in normal application queries
- Data recovery: restore accidentally deleted objects without database backups or manual intervention
- Referential integrity: soft-delete dependent objects while preserving foreign-key relationships for reporting
- Multi-tenant systems: hide deleted tenant data from queries while keeping it available for account recovery or legal holds
- Admin interfaces: provide undo/restore functionality in Django admin for recently deleted records
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides soft-delete functionality for Django models, allowing objects to be masked from queries instead of permanently removed from the database.
Yes, with conditions. The package is well-established (in top 5000 PyPI by downloads), has no known vulnerabilities, and low install friction. However, the aging maintenance status (527 days since last release) and lack of explicit Python 3.12+ / Django 5.1+ support in the fact sheet warrant verification before adopting in new projects targeting the latest Django versions. Suitable for existing Django applications needing soft-delete without major framework upgrades.
Install
django-safedelete on PyPI
pip
pip install django-safedeleteuv
uv add django-safedeletepoetry
poetry add django-safedeleteInstalling django-safedelete
Before you install
Low install friction with only Django and packaging as runtime dependencies. Maintenance status is aging—last release was 527 days ago (2025-03-05), though the repository remains active with recent commits and no archived status.
License in practice
BSD license (permissive) imposes no significant restrictions on use or redistribution.
Quickstart
pip install django-safedelete
# In settings.py, add 'safedelete' to INSTALLED_APPS
from safedelete.models import SafeDeleteModel, SOFT_DELETE
from django.db import models
class Article(SafeDeleteModel):
_safedelete_policy = SOFT_DELETE
title = models.CharField(max_length=100)
article = Article.objects.create(title='Test')
article.delete() # Masked, not removed
Article.objects.filter(title='Test').exists() # False (hidden by default)
Article.all_objects.filter(title='Test').exists() # True (includes soft-deleted)
Requires Django as a runtime dependency; ensure Django version compatibility with the branch you install (1.4.x supports Django 3.2+, 4.0+, 4.1+, 4.2+).
Verify before relying
- Whether current version supports Django 5.0+ and Python 3.12+ despite changelog noting 1.4.0 added Django 5.0 support
- Specific behavior differences between the five deletion policies (SOFT_DELETE, SOFT_DELETE_CASCADE, HARD_DELETE, HARD_DELETE_NOCASCADE, NO_DELETE) in edge cases
- Performance impact on large datasets with many soft-deleted records
Package facts
| License | BSD (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — Django, packaging |
| Maintenance | aging — 527 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,206,242/month — #4,221 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: django_safedelete-1.4.1-py3-none-any.whl
Keywords: django, delete, safedelete, softdelete
Tags
More Database packages
psycopg2-binary is a PostgreSQL database…
copyleft · top 1,000 on PyPI
redisPython client library for connecting to and…
permissive · top 1,000 on PyPI
ydbYDB Python SDK is the official client library…
permissive · top 1,000 on PyPI
snowflake-connector-pythonConnects Python applications to Snowflake data…
permissive · top 1,000 on PyPI
sqlparsesqlparse tokenizes SQL text into a tree of…
permissive · top 1,000 on PyPI
dbt-adaptersProvides base adapter protocols and shared…
permissive · top 1,000 on PyPI
django-soft-deleteAdds soft deletion to Django models by marking…
permissive · top 15,000 on PyPI
sqlalchemy-easy-softdeleteAdds soft-deletion support to SQLAlchemy models…
permissive · top 15,000 on PyPI
django-cryptography-5Provides encrypted model fields and…
permissive · top 15,000 on PyPI
django-reversiondjango-reversion adds version control to Django…
permissive · top 5,000 on PyPI
django-model-utilsProvides reusable model mixins and field…
permissive · top 5,000 on PyPI
django-crumDjango-CRUM stores the current request and user…
permissive · top 15,000 on PyPI
django-sortedm2mProvides a drop-in replacement for Django's…
permissive · top 15,000 on PyPI
django-cryptographyWraps Python's cryptography library to add…
permissive · top 15,000 on PyPI
django-cryptography-django5Encrypts and decrypts data in Django models…
permissive · top 15,000 on PyPI