Skip to main content

No project description provided

Project description

django-resurrected

Deleted is just a state. Bring your models back.

PyPI Version Python Versions


django-resurrected provides soft-delete functionality for Django projects. Instead of permanently removing objects, it marks them as “removed,” making them easy to restore later. The package supports relation-aware deletion and restoration, along with configurable retention.

Table of Contents

Quick Start

1. Install

pip install django-resurrected

2. Update Your Models

Inherit from SoftDeleteModel to enable soft-deletion and restoration:

from django.db import models
from django_resurrected.models import SoftDeleteModel

class Author(SoftDeleteModel):
    name = models.CharField(max_length=100)

class Book(SoftDeleteModel):
    author = models.ForeignKey(Author, on_delete=models.CASCADE)
    title = models.CharField(max_length=200)

class BookMeta(SoftDeleteModel):
    book = models.ForeignKey(Book, on_delete=models.CASCADE)
    format = models.CharField(max_length=20)

3. Use the Enhanced Managers

Each manager now has:

  • .objects — all records (active + removed)
  • .active_objects — only active (not removed)
  • .removed_objects — only soft-deleted

4. Remove (Soft-Delete) with Cascading

Removing a parent will also remove its related children:

>>> author = Author.objects.create(name="Frank")
>>> book = Book.objects.create(author=author, title="Dune")
>>> meta = BookMeta.objects.create(book=book, format="ebook")

>>> Author.active_objects.count()
1
>>> Book.active_objects.count()
1
>>> BookMeta.active_objects.count()
1

>>> author.remove()
(3, {'test_app.Author': 1, 'test_app.Book': 1, 'test_app.BookMeta': 1})

>>> Author.active_objects.count()
0
>>> Book.active_objects.count()
0
>>> BookMeta.active_objects.count()
0

5. Restore: Selective or Cascading

Restore only the top-level object

>>> author.restore()
(1, {'test_app.Author': 1})

>>> Author.active_objects.count()
1
>>> Book.active_objects.count()
0
>>> BookMeta.active_objects.count()
0

Restore with all related objects

>>> author.restore(with_related=True)
(3, {'test_app.Author': 1, 'test_app.Book': 1, 'test_app.BookMeta': 1})

>>> Author.active_objects.count()
1
>>> Book.active_objects.count()
1
>>> BookMeta.active_objects.count()
1

Restore from a mid-level object

>>> author.remove()
(3, {'test_app.Author': 1, 'test_app.Book': 1, 'test_app.BookMeta': 1})

>>> book.restore()
(2, {'test_app.Book': 1, 'test_app.Author': 1})

>>> Author.active_objects.count()
1
>>> Book.active_objects.count()
1
>>> BookMeta.active_objects.count()
0

Configuration

You can customize the retention period by setting the retention_days attribute on your model. Set it to None to keep objects indefinitely.

# your_app/models.py
from django_resurrected.models import SoftDeleteModel

class ImportantDocument(SoftDeleteModel):
    # Keep forever
    retention_days = None
    content = models.TextField()

class TemporaryFile(SoftDeleteModel):
    # Keep for one week
    retention_days = 7
    data = models.BinaryField()

To permanently remove objects that have exceeded their retention limit, call purge():

>>> TemporaryFile.removed_objects.all().purge()

License

This project is licensed under the MIT License.

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_resurrected-0.2.1.tar.gz (43.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_resurrected-0.2.1-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file django_resurrected-0.2.1.tar.gz.

File metadata

  • Download URL: django_resurrected-0.2.1.tar.gz
  • Upload date:
  • Size: 43.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for django_resurrected-0.2.1.tar.gz
Algorithm Hash digest
SHA256 8532995e5cacf617ade8c5b539f30e41d79e1905dd4e25bc65ac8b543afc4a5f
MD5 3c45d1b76e5b9b237fec8995f0376847
BLAKE2b-256 85ce7523a4c1e0dbcebe3e7e1258ee508a07972f43c5e581fa2b75b9c7912c3d

See more details on using hashes here.

File details

Details for the file django_resurrected-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_resurrected-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a75d7f89e53349016845479f0db1232dbf1b45bbb718f8ad9e1d706a18981602
MD5 5c9bf2928c33313658064f7379d8ea70
BLAKE2b-256 3755c0dfe5971837f12076e85d27cf77fde1765540ea50e11980f5bd201ed428

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