Skip to main content

Abstraction to logical/soft delete in django models

Project description

Django Soft Delete

Build Status codecov

Django Soft Delete gives Django models the ability to soft delete(logical delete). it also gives the ability to restore or undelete soft-deleted instances.

Basic usage

  1. Clone this repo and then $pip install django-soft-delete
  2. Add softdelete model to INSTALLED_APPS
  3. Inherit all models you want to have this functionality from softdelete.models.SoftDeleteModel
>>> MyModel.objects.create(name='Anakin')
>>> MyModel.objects.create(name='Luke')
>>> MyModel.objects.create(name='Yoda')

>>> luke  = MyModel.objecs.filter(name='Luke')
>>> MyModel.objecs.filter(name='Luke').delete()

>>> MyModel.objects.count()

>>> MyModel.raw_objects.count()

>>> MyModel.objects.get(
>>> MyModel.objects.count()


from softdelete.models import SoftDeleteModel

class MyModel(SoftDeleteModel):
    name = models.CharField(max_length=30)

You can also use the SoftDelete django manager to extends your custom manager funcionalities. Do it like so:
from softdelete.managers import SoftDeleteManager

class MyModelManager(SoftDeleteManager):

    def create_john_smith(self):
        self.model.objects.create(name='Jonh Smith')
from django.db import models
from my_model_manager import MyModelManager

class MyModel(SoftDeleteModel):
    name = models.CharField(max_length=30)

    objects = models.Manager()
    my_manager = MyModelManager()

It's possible to have access to delete instances through an alternative manager raw_objects

    for inst in MyModel.raw_objects.all():

Project details

Release history Release notifications

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for soft-delete, version 0.2.2
Filename, size File type Python version Upload date Hashes
Filename, size soft_delete-0.2.2-py3-none-any.whl (4.7 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size soft-delete-0.2.2.tar.gz (3.9 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page