<div align="center">
<h1 align="center">django-resurrected</h1>
<p align="center">
<strong>Deleted is just a state. Bring your models back.</strong>
</p>
<p align="center">
<a href="https://pypi.org/project/django-resurrected/"><img src="https://img.shields.io/pypi/v/django-resurrected.svg" alt="PyPI Version"></a>
<a href="https://github.com/krzysiek951/django-resurrected/actions"><img src="https://img.shields.io/github/actions/workflow/status/krzysiek951/django-resurrected/main.yml?branch=main" alt="Build Status"></a>
<a href="https://codecov.io/gh/krzysiek951/django-resurrected"><img src="https://img.shields.io/codecov/c/github/krzysiek951/django-resurrected.svg" alt="Coverage Status"></a>
<a href="https://pypi.org/project/django-resurrected/"><img src="https://img.shields.io/pypi/pyversions/django-resurrected.svg" alt="Python Versions"></a>
</p>
</div>
---
`django-resurrected` provides robust soft-deletion capabilities for your Django projects. Instead of permanently deleting objects from your database, this package marks them as "removed," allowing you to restore them later. This is an invaluable safety net against accidental data loss.
## Why `django-resurrected`?
- **Prevent Data Loss**: Protect your application's data from accidental deletion by users or developers.
- **Maintain Data Integrity**: Cascading soft-deletes ensure that related objects are handled correctly, preserving relationships.
- **Full Control**: Flexible model managers give you granular control over querying active, removed, or all objects.
- **Easy Integration**: Simply inherit from `SoftDeleteModel` to add soft-deletion capabilities to any model.
## Table of Contents
- [Features](#features)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Usage Guide](#usage-guide)
- [Model Managers](#model-managers)
- [Deleting and Restoring](#deleting-and-restoring)
- [Permanent Deletion (Purging)](#permanent-deletion-purging)
- [Configuration](#configuration)
- [License](#license)
## Features
- ✅ **Effortless Soft Deletion**: "Delete" objects without permanently losing them.
- ✅ **Simple Restoration**: Restore soft-deleted objects with a single command.
- ✅ **Cascading Deletes**: Automatically soft-delete related objects.
- ✅ **Configurable Retention Periods**: Control how long to keep removed objects before they can be purged.
- ✅ **Full Typing Support**: Enjoy a modern development experience with complete type hints.
## Installation
Install the package from PyPI:
```bash
pip install django-resurrected
```
## Quick Start
1. **Inherit from `SoftDeleteModel`**: Update your model to inherit from `django_resurrected.models.SoftDeleteModel`.
2. **Use the New Managers**: Your model will now have `objects`, `active_objects`, and `removed_objects` managers.
Here’s a quick example:
```python
# your_app/models.py
from django.db import models
from django_resurrected.models import SoftDeleteModel
class BlogPost(SoftDeleteModel):
title = models.CharField(max_length=200)
content = models.TextField()
def __str__(self):
return self.title
```
Now you can manage your model instances safely:
```python
>>> # Create a new post
>>> post = BlogPost.objects.create(title="My First Post")
>>> BlogPost.active_objects.count()
1
>>> # Soft-delete the post
>>> post.remove()
>>> BlogPost.active_objects.count()
0
>>> BlogPost.removed_objects.count()
1
>>> # Restore the post
>>> post.restore()
>>> BlogPost.active_objects.count()
1
```
## Usage Guide
### Model Managers
`SoftDeleteModel` equips your model with three distinct managers:
- `YourModel.objects`: The default manager. Returns **all** objects (both active and removed).
- `YourModel.active_objects`: Returns only active (not deleted) objects. Use this for most of your application logic.
- `YourModel.removed_objects`: Returns only soft-deleted objects.
### Deleting and Restoring
You can perform soft-delete and restore operations on both individual instances and querysets.
- `instance.remove()`: Soft-deletes a single model instance and its related objects.
- `instance.restore()`: Restores a soft-deleted instance and its related objects.
- `queryset.remove()`: Soft-deletes all objects in a queryset.
- `queryset.restore()`: Restores all objects in a queryset.
### Permanent Deletion (Purging)
You can permanently delete objects that have passed their retention period. By default, objects are retained for 30 days.
```python
# Check if an object is expired and ready for purging
>>> post.is_expired
False
# Purge all expired objects for a model
>>> BlogPost.removed_objects.expired().purge()
```
## Configuration
You can customize the retention period by setting the `retention_days` attribute on your model. Set it to `None` to keep objects indefinitely.
```python
# 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()
```
## License
This project is licensed under the MIT License.
Raw data
{
"_id": null,
"home_page": null,
"name": "django-resurrected",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "recovery, restore, resurrect, retention, soft-delete, softdelete, trash, undelete",
"author": null,
"author_email": "Krzysztof Czopkiewicz <krzysiek951@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/c6/6f/b6d6e530c9ad10e8871a0f38095207ca985e9cf086d25aea63915d517fd0/django_resurrected-0.1.2.tar.gz",
"platform": null,
"description": "<div align=\"center\">\n <h1 align=\"center\">django-resurrected</h1>\n <p align=\"center\">\n <strong>Deleted is just a state. Bring your models back.</strong>\n </p>\n <p align=\"center\">\n <a href=\"https://pypi.org/project/django-resurrected/\"><img src=\"https://img.shields.io/pypi/v/django-resurrected.svg\" alt=\"PyPI Version\"></a>\n <a href=\"https://github.com/krzysiek951/django-resurrected/actions\"><img src=\"https://img.shields.io/github/actions/workflow/status/krzysiek951/django-resurrected/main.yml?branch=main\" alt=\"Build Status\"></a>\n <a href=\"https://codecov.io/gh/krzysiek951/django-resurrected\"><img src=\"https://img.shields.io/codecov/c/github/krzysiek951/django-resurrected.svg\" alt=\"Coverage Status\"></a>\n <a href=\"https://pypi.org/project/django-resurrected/\"><img src=\"https://img.shields.io/pypi/pyversions/django-resurrected.svg\" alt=\"Python Versions\"></a>\n </p>\n</div>\n\n---\n\n`django-resurrected` provides robust soft-deletion capabilities for your Django projects. Instead of permanently deleting objects from your database, this package marks them as \"removed,\" allowing you to restore them later. This is an invaluable safety net against accidental data loss.\n\n## Why `django-resurrected`?\n\n- **Prevent Data Loss**: Protect your application's data from accidental deletion by users or developers.\n- **Maintain Data Integrity**: Cascading soft-deletes ensure that related objects are handled correctly, preserving relationships.\n- **Full Control**: Flexible model managers give you granular control over querying active, removed, or all objects.\n- **Easy Integration**: Simply inherit from `SoftDeleteModel` to add soft-deletion capabilities to any model.\n\n## Table of Contents\n\n- [Features](#features)\n- [Installation](#installation)\n- [Quick Start](#quick-start)\n- [Usage Guide](#usage-guide)\n - [Model Managers](#model-managers)\n - [Deleting and Restoring](#deleting-and-restoring)\n - [Permanent Deletion (Purging)](#permanent-deletion-purging)\n- [Configuration](#configuration)\n- [License](#license)\n\n## Features\n\n- \u2705 **Effortless Soft Deletion**: \"Delete\" objects without permanently losing them.\n- \u2705 **Simple Restoration**: Restore soft-deleted objects with a single command.\n- \u2705 **Cascading Deletes**: Automatically soft-delete related objects.\n- \u2705 **Configurable Retention Periods**: Control how long to keep removed objects before they can be purged.\n- \u2705 **Full Typing Support**: Enjoy a modern development experience with complete type hints.\n\n## Installation\n\nInstall the package from PyPI:\n\n```bash\npip install django-resurrected\n```\n\n## Quick Start\n\n1. **Inherit from `SoftDeleteModel`**: Update your model to inherit from `django_resurrected.models.SoftDeleteModel`.\n2. **Use the New Managers**: Your model will now have `objects`, `active_objects`, and `removed_objects` managers.\n\nHere\u2019s a quick example:\n\n```python\n# your_app/models.py\nfrom django.db import models\nfrom django_resurrected.models import SoftDeleteModel\n\nclass BlogPost(SoftDeleteModel):\n title = models.CharField(max_length=200)\n content = models.TextField()\n\n def __str__(self):\n return self.title\n```\n\nNow you can manage your model instances safely:\n\n```python\n>>> # Create a new post\n>>> post = BlogPost.objects.create(title=\"My First Post\")\n>>> BlogPost.active_objects.count()\n1\n\n>>> # Soft-delete the post\n>>> post.remove()\n>>> BlogPost.active_objects.count()\n0\n>>> BlogPost.removed_objects.count()\n1\n\n>>> # Restore the post\n>>> post.restore()\n>>> BlogPost.active_objects.count()\n1\n```\n\n## Usage Guide\n\n### Model Managers\n\n`SoftDeleteModel` equips your model with three distinct managers:\n\n- `YourModel.objects`: The default manager. Returns **all** objects (both active and removed).\n- `YourModel.active_objects`: Returns only active (not deleted) objects. Use this for most of your application logic.\n- `YourModel.removed_objects`: Returns only soft-deleted objects.\n\n### Deleting and Restoring\n\nYou can perform soft-delete and restore operations on both individual instances and querysets.\n\n- `instance.remove()`: Soft-deletes a single model instance and its related objects.\n- `instance.restore()`: Restores a soft-deleted instance and its related objects.\n- `queryset.remove()`: Soft-deletes all objects in a queryset.\n- `queryset.restore()`: Restores all objects in a queryset.\n\n### Permanent Deletion (Purging)\n\nYou can permanently delete objects that have passed their retention period. By default, objects are retained for 30 days.\n\n```python\n# Check if an object is expired and ready for purging\n>>> post.is_expired\nFalse\n\n# Purge all expired objects for a model\n>>> BlogPost.removed_objects.expired().purge()\n```\n\n## Configuration\n\nYou can customize the retention period by setting the `retention_days` attribute on your model. Set it to `None` to keep objects indefinitely.\n\n```python\n# your_app/models.py\nfrom django_resurrected.models import SoftDeleteModel\n\nclass ImportantDocument(SoftDeleteModel):\n # Keep forever\n retention_days = None\n content = models.TextField()\n\nclass TemporaryFile(SoftDeleteModel):\n # Keep for one week\n retention_days = 7\n data = models.BinaryField()\n```\n\n## License\n\nThis project is licensed under the MIT License.",
"bugtrack_url": null,
"license": null,
"summary": null,
"version": "0.1.2",
"project_urls": {
"Repository": "https://github.com/krzysiek951/django-resurrected"
},
"split_keywords": [
"recovery",
" restore",
" resurrect",
" retention",
" soft-delete",
" softdelete",
" trash",
" undelete"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "c76ab2760b6e97417a6203c1afa5f6aaf3390a381586c5a4bc6e6342fe1210a4",
"md5": "a6e51a90b063a42c90cb392524f15326",
"sha256": "983c9a7fa2724431a72f399b6f0a742bceffa2ab8e8c0bdb57939e7fd01a5a09"
},
"downloads": -1,
"filename": "django_resurrected-0.1.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a6e51a90b063a42c90cb392524f15326",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 7021,
"upload_time": "2025-07-29T20:37:02",
"upload_time_iso_8601": "2025-07-29T20:37:02.371499Z",
"url": "https://files.pythonhosted.org/packages/c7/6a/b2760b6e97417a6203c1afa5f6aaf3390a381586c5a4bc6e6342fe1210a4/django_resurrected-0.1.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "c66fb6d6e530c9ad10e8871a0f38095207ca985e9cf086d25aea63915d517fd0",
"md5": "a14faf16a18889fedafa015aa6a537ed",
"sha256": "efe3b0cc4122f9b41f4dd7ba18a12125fe7a7b7321fafd46b84a5a5d7154fff1"
},
"downloads": -1,
"filename": "django_resurrected-0.1.2.tar.gz",
"has_sig": false,
"md5_digest": "a14faf16a18889fedafa015aa6a537ed",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 43399,
"upload_time": "2025-07-29T20:37:03",
"upload_time_iso_8601": "2025-07-29T20:37:03.885716Z",
"url": "https://files.pythonhosted.org/packages/c6/6f/b6d6e530c9ad10e8871a0f38095207ca985e9cf086d25aea63915d517fd0/django_resurrected-0.1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-29 20:37:03",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "krzysiek951",
"github_project": "django-resurrected",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"tox": true,
"lcname": "django-resurrected"
}