django-fsm data immutability support
Project description
django fsm data immutability support
django-fsm-freeze provides a django model mixin for data immutability based on django-fsm.
Installation
pip install django-fsm-freeze
Usage
- Add
FreezableFSMModelMixin
to your django-fsm model - Specify the
FROZEN_IN_STATES
in which the object should be frozen, meaning the value of its fields/attributes cannot be changed. - (optional) Customize the
NON_FROZEN_FIELDS
for mutability
When an object is in a frozen state, by default all of its fields are immutable,
except for the state
field which needs to be mutable for
django-fsm to work.
In case we still want to mutate certain fields when the object is frozen, we can override
the NON_FROZEN_FIELDS
to allow it.
When overriding the NON_FROZEN_FIELDS
, be careful to include state
for the reason
mentioned above.
from django.db import models
from django_fsm import FSMField
from django_fsm_freeze.models import FreezableFSMModelMixin
class MyDjangoFSMModel(FreezableFSMModelMixin, models.Model):
# In this example, when object is in the 'active' state, it is immutable.
FROZEN_IN_STATES = ('active', )
NON_FROZEN_FIELDS = FreezableFSMModelMixin.NON_FROZEN_FIELDS + (
'a_mutable_field',
)
# This field is mutable even when the object is in the frozen state.
a_mutable_field = models.BooleanField()
# django-fsm specifics: state, transitions, etc.
state = FSMField(default='new')
# ...
See example usage also in https://github.com/ming-tung/django-fsm-freeze/blob/main/mytest/models.py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for django_fsm_freeze-0.1.7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b5477048deac02974df9c45c9b732022f86013e871544752a34efd3f79481db |
|
MD5 | c4b85377aba06e59b443d814674a75bc |
|
BLAKE2b-256 | 6fb720d4d7469646e935b953b54df8c6d56e614fc581108b96486366f6c9f59f |