Skip to main content

Abstract Django models for soft removal

Project description

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

Project details


Download files

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

Source Distribution

django-soft-remover-0.5.0.tar.gz (5.5 kB view hashes)

Uploaded Source

Built Distribution

django_soft_remover-0.5.0-py3-none-any.whl (7.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page