model-version


Namemodel-version JSON
Version 0.2.2 PyPI version JSON
download
home_pagehttps://github.com/aleosd/model-version
SummaryDjango model version mixin
upload_time2024-01-02 21:07:17
maintainer
docs_urlNone
authorAlex
requires_python>=3.8,<4.0
licenseApache-2.0
keywords django model version
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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](#installation)
* [Usage](#usage)
  * [Disable Versioning](#disable-versioning)
* [Limitations](#limitations)

## Installation

To install the library use pip:

```shell
pip install model_version
```

## Usage

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

```python
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:

```shell
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:

```python
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:

```python
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.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/aleosd/model-version",
    "name": "model-version",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "",
    "keywords": "django,model,version",
    "author": "Alex",
    "author_email": "osdalex@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/fc/c8/8f56851c9ff454bfe9d36953ffdf1e9d005b29efb05cd1be4344caa1e0d9/model_version-0.2.2.tar.gz",
    "platform": null,
    "description": "# Model version\n\n**Model version** allows to track changes to Django model instances. Each time\nan instance is updated, its `version` number is incremented and old values are\ncopied to a new record, that represents previous version of the current instance.\n\n* [Installation](#installation)\n* [Usage](#usage)\n  * [Disable Versioning](#disable-versioning)\n* [Limitations](#limitations)\n\n## Installation\n\nTo install the library use pip:\n\n```shell\npip install model_version\n```\n\n## Usage\n\nTo enable model versioning `ModelVersion` should be used as one of base classes\na model inherits from:\n\n```python\nfrom model_version import ModelVersion\n\n\nclass MyModel(ModelVersion):\n    ...\n```\n\nThis will add three new fields to the model:\n\n* `version` - integer number starting from `0` (default version start number)\n* `version_id` - `uuid4` that represents different versions of the same record\n* `version_created_at` - timestamp record\n\nCreate and apply migrations with the new fields:\n\n```shell\npython ./manage.py makemigration\npython ./manage.py migrate\n```\n\n### Disable versioning\n\nThere's a context manager `disabled_versioning` that allows to disable model\nversioning for a specific operation:\n\n```python\nfrom model_version import disabled_versioning\nfrom myapp.models import MyModel\n\nrecord = MyModel.objects.create(name=\"foo\")\nassert record.version == 0\n\nwith disabled_versioning():\n    record.name = \"bar\"\n    record.save()\n    \nassert record.version == 0\n```\n\nContext variable based on `contextvars` is used under the hood. It can be used\ndirectly to manually manage version creation process:\n\n```python\nfrom model_version.settings import versioning_is_disabled\n\n\nreset_token = versioning_is_disabled.set(True)\n...  # non-versioned operations go here\nversioning_is_disabled.reset(reset_token)\n```\n\n## Limitations\n\n1. Doesn't work with bulk operations.\n2. Requires additional DB query on save.\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Django model version mixin",
    "version": "0.2.2",
    "project_urls": {
        "Documentation": "https://github.com/aleosd/model-version",
        "Homepage": "https://github.com/aleosd/model-version",
        "Repository": "https://github.com/aleosd/model-version.git"
    },
    "split_keywords": [
        "django",
        "model",
        "version"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1526eb5c8425e653e220d2a113ad8b89e06d821f0316ae5ecb8fb43ae585b24e",
                "md5": "0d45f9244bfe62d57a55cad07b875117",
                "sha256": "6b0b0cc23adf8b04c9d22e736abcf05287c17f5d863ce1696fedb6b4d7cebac1"
            },
            "downloads": -1,
            "filename": "model_version-0.2.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0d45f9244bfe62d57a55cad07b875117",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 7863,
            "upload_time": "2024-01-02T21:07:16",
            "upload_time_iso_8601": "2024-01-02T21:07:16.165249Z",
            "url": "https://files.pythonhosted.org/packages/15/26/eb5c8425e653e220d2a113ad8b89e06d821f0316ae5ecb8fb43ae585b24e/model_version-0.2.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fcc88f56851c9ff454bfe9d36953ffdf1e9d005b29efb05cd1be4344caa1e0d9",
                "md5": "6a8d77bbeac0dadb0bbae9132273e3a8",
                "sha256": "41e34ee6c8dc6a4971eeff4f3a5e70453e3f15586cb938f24d4177e44fac0401"
            },
            "downloads": -1,
            "filename": "model_version-0.2.2.tar.gz",
            "has_sig": false,
            "md5_digest": "6a8d77bbeac0dadb0bbae9132273e3a8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 7038,
            "upload_time": "2024-01-02T21:07:17",
            "upload_time_iso_8601": "2024-01-02T21:07:17.487463Z",
            "url": "https://files.pythonhosted.org/packages/fc/c8/8f56851c9ff454bfe9d36953ffdf1e9d005b29efb05cd1be4344caa1e0d9/model_version-0.2.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-02 21:07:17",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "aleosd",
    "github_project": "model-version",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "model-version"
}
        
Elapsed time: 0.54981s