Classifiers

Project Description

Easily make all of a django model’s fields immutable after saving.
You can customize it to make some fields mutable.
You can change when it can be mutable
(e.g. whenever the field’s value is nil, or only when a particular ‘lock field’ is false)

Tell ImmutableModel which fields should not be allowed to change.
NB: you can’t specify mutable_fields AND immutable_fields.
This value must be a tuple or a list and contain the names of the fields
as strings.:

If an attempt is made to change an immutable field, should we quietly
prevent it.

Set this value to False to raise a ValueError when an immutable
field is changed.:

class ImmutableMeta:
immutable_quiet = False

immutable_lock_field

This determines when to enforce immutability. By default it is equal to immutable_model.models.PK_FIELD.
This means that when the PK_FIELD is full (typically when saved) the model is immutable, but before it is
saved it is mutable.
Alternatively you can specify a field by name, or you can set it to None, which means that you can’t change
immutable fields once they are set (even before saving).

class ImmutableMeta:

immutable_lock_field = [‘is_locked’]

settings.py

IMMUTABLE_QUIET

Set this to False to make all immutable_fields raise an Exception when attempting
to be changed.