Skip to main content

Model version

Model version allows to track changes to Django model instances. Each time an instance is updated, its version number is incremented and old values are copied to a new record, that represents previous version of the current instance.

Installation

To install the library use pip:

pip install model_version

Usage

To enable model versioning ModelVersion should be used as one of base classes a model inherits from:

from model_version import ModelVersion


class MyModel(ModelVersion):
    ...

This will add three new fields to the model:

  • version - integer number starting from 0 (default version start number)
  • version_id - uuid4 that represents different versions of the same record
  • version_created_at - timestamp record

Create and apply migrations with the new fields:

python ./manage.py makemigration
python ./manage.py migrate

Disable versioning

There's a context manager disabled_versioning that allows to disable model versioning for a specific operation:

from model_version import disabled_versioning
from myapp.models import MyModel

record = MyModel.objects.create(name="foo")
assert record.version == 0

with disabled_versioning():
    record.name = "bar"
    record.save()
    
assert record.version == 0

Context variable based on contextvars is used under the hood. It can be used directly to manually manage version creation process:

from model_version.settings import versioning_is_disabled


reset_token = versioning_is_disabled.set(True)
...  # non-versioned operations go here
versioning_is_disabled.reset(reset_token)

Limitations

  1. Doesn't work with bulk operations.
  2. Requires additional DB query on save.

Metadata

Release files for model-version 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for model-version 0.2.2
File Size Uploaded Provenance Actions
model_version-0.2.2.tar.gz 7.0 kB Without provenance Details for model_version-0.2.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for model-version 0.2.2
File Interpreter ABI Platform Actions
model_version-0.2.2-py3-none-any.whl Python 3 none any Details for model_version-0.2.2-py3-none-any.whl

Total release size: 14.9 kB

Release files / model_version-0.2.2.tar.gz

Download URL model_version-0.2.2.tar.gz
Size 7.0 kB
Tags Source
SHA-256 checksum
How to use checksums
41e34ee6c8dc6a4971eeff4f3a5e70453e3f15586cb938f24d4177e44fac0401
BLAKE2b-256 checksum
How to use checksums
fcc88f56851c9ff454bfe9d36953ffdf1e9d005b29efb05cd1be4344caa1e0d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.12.0 Darwin/22.6.0

Release files / model_version-0.2.2-py3-none-any.whl

Download URL model_version-0.2.2-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6b0b0cc23adf8b04c9d22e736abcf05287c17f5d863ce1696fedb6b4d7cebac1
BLAKE2b-256 checksum
How to use checksums
1526eb5c8425e653e220d2a113ad8b89e06d821f0316ae5ecb8fb43ae585b24e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.12.0 Darwin/22.6.0

Security for model-version 0.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page