Skip to content

pikhovkin/django-soft-remover

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

django-soft-remover

GitHub Actions PyPI PyPI - Python Version framework - Django PyPI - Django Version PyPI - License

Abstract Django models for soft removal.

It supports unique field indices specified with

  • unique
  • unique_together
  • UniqueConstraint (without expressions or conditions)

Just add the remver field to the composite unique index if you need to maintain uniqueness between removed versions.

Installation

$ pip install django-soft-remover

Example of use

from django.db import models

from soft_remover.models import SoftRemovableModel, SoftRestorableModel


class ManyUniqueTogetherRem(SoftRemovableModel):
    category = models.CharField(max_length=32)
    name = models.CharField(max_length=32)
    tag = models.CharField(max_length=32)
    value = models.PositiveSmallIntegerField()

    class Meta:
        unique_together = (('category', 'name', 'remver'), ('category', 'tag', 'remver'))

        
class UniqueWithConstraint(SoftRemovableModel):
    name = models.CharField(max_length=32)

    class Meta:
        constraints = [
            models.UniqueConstraint(fields=['name', 'remver'], name='uwc_name_remver'),
        ]

        
class ManyUniqueTogetherRes(SoftRestorableModel):
    category = models.CharField(max_length=32)
    name = models.CharField(max_length=32)
    tag = models.CharField(max_length=32)
    value = models.PositiveSmallIntegerField()

    class Meta:
        unique_together = (('category', 'name'), ('category', 'tag'))

See more examples in test models.

License

MIT

Releases

No releases published

Packages

No packages published

Languages