https://github.com/yucealiosman/soft-delete
This Django application provides an abstract model, that allows you to transparently retrieve or delete your objects, without having them deleted from your database.
https://github.com/yucealiosman/soft-delete
django python soft-delete
Last synced: 6 months ago
JSON representation
This Django application provides an abstract model, that allows you to transparently retrieve or delete your objects, without having them deleted from your database.
- Host: GitHub
- URL: https://github.com/yucealiosman/soft-delete
- Owner: yucealiosman
- License: mit
- Created: 2021-06-30T08:54:21.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-09-17T11:34:05.000Z (almost 5 years ago)
- Last Synced: 2025-10-28T17:27:09.214Z (9 months ago)
- Topics: django, python, soft-delete
- Language: Python
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
- License: LICENSE
Awesome Lists containing this project
README
**This package provides an abstract django model, that allows you to transparently retrieve or delete your objects, without having them deleted from your database.**
### Example of usage
#### imports
```python
from django_soft_delete.models import SoftDeletionModel
```
#### Create a new model class derived from SoftDeletionModel.
```python
class User(SoftDeletionModel):
name = models.CharField(max_length=100)
```
#### And just invoke delete method, that's all.
```python
user = User(name='test')
user.save()
user.delete()
```
##### You can use all functionalities with queryset as well.
```python
users = User.objects.filter(name='test')
users.delete()
```
##### This user will be masked, but not deleted from the database.
```python
User.object.filter(name='test') #returns empty query string.
User.all_objects.filter(name='test) #returns deleted user instance which has non empty deleted_at field.
```
##### In order to create model deletion relations, you have to import deletion.py and use the related on_delete functions like CASCADE, PROTECT, etc.
```python
from django_soft_delete.deletion import CASCADE
from django_soft_delete.models import SoftDeletionModel
class User(SoftDeletionModel):
name = models.CharField(max_length=100)
class Profile(SoftDeletionModel):
name = models.CharField(max_length=100)
user = models.ForeignKey(User, on_delete=CASCADE,
verbose_name=_('User'), null=True,
blank=True)
```
##### In order to revive your soft-deleted records, you can use undelete method.
```python
user = User(name='test')
user.save()
user.delete()
user.undelete()
```
##### In order to delete your instance permanently from your database, you can use hard_delete method.
```python
user = User(name='test')
user.save()
user.hard_delete()
```
## Installation
- pip install soft-django-delete
##### Add 'django_soft_delete' in your INSTALLED_APPS:
```python
INSTALLED_APPS = [
'django_soft_delete',
[...]
]
```