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

Installation

Install the package from PyPI:

pip install django-resurrected

Quick Start

Here’s how to get started:

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.0.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.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_resurrected-0.2.0.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.0.tar.gz
Algorithm Hash digest
SHA256 187c72e20126aae9106b51ce2f3c43edabe6541d298f68aa11c6f1cbff51810a
MD5 8513574e8aefd98a6c8872e8335a5f78
BLAKE2b-256 b25116570a65069eff68632b42fddc93b12c424a3e3da7a91e1dd85eda3972a3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_resurrected-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0a3000588481b82c8e0769cbe8aebf3ceffedf9d85c2bcf95bee517e9a916b14
MD5 a0190f69e9e6a6bc469461e00960f285
BLAKE2b-256 c26b85ae07c6edcba315e5976eb3fab7a9a8afee5218ce6491ed247fb6595d26

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