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.
$ pip install django-soft-remover
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.
MIT