django-snapshot-field


Namedjango-snapshot-field JSON
Version 0.1.5 PyPI version JSON
download
home_pagehttps://github.com/Apkawa/django-snapshot-field
SummaryA field in a model that store a snapshot of a model object and retrieves it as a read-only model object
upload_time2025-01-11 06:50:22
maintainerNone
docs_urlNone
authorApkawa
requires_pythonNone
licenseMIT
keywords django
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            [![ci](https://github.com/Apkawa/django-snapshot-field/actions/workflows/ci.yml/badge.svg)](https://github.com/Apkawa/django-snapshot-field/actions/workflows/ci.yml)

[![PyPi](https://img.shields.io/pypi/v/django-snapshot-field.svg)](https://pypi.python.org/pypi/django-snapshot-field)
[![PyPI](https://img.shields.io/pypi/pyversions/django-snapshot-field.svg)](https://pypi.python.org/pypi/django-snapshot-field)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)

A field in a model that stores a snapshot of a model object and retrieves it as a read-only model object

# Installation

```bash
pip install django-snapshot-field
```

or from git

```bash
pip install -e git+https://githib.com/Apkawa/django-snapshot-field.git#egg=django-snapshot-field
```

## Django and python version compatibles


| Python<br/>Django | 3.8 | 3.9 | 3.10 | 3.11 | 3.12 | 3.13 |
|:-----------------:|-----|----|------|------|------|------|
|        4.2        | ✅   | ✅  | ✅    | ✅    | ✅    | ✅    |
|        5.0        | ❌   | ❌   | ✅    | ✅    | ✅    | ✅    |
|        5.1        | ❌   | ❌   | ✅    | ✅    | ✅    | ✅    |
|        5.2        | ❌   | ❌   | ✅    | ✅    | ✅    | ✅    |



# Usage

```python
from django.db import models
from snapshot_field.fields import SnapshotModelField

class Example(models.Model):
    name = models.CharField(max_length=20)

class ExampleReference(models.Model):
    name = models.CharField(max_length=20)
    ref = models.ForeignKey(Example)


class ExampleSnapshotModel(models.Model):
    snapshot = SnapshotModelField(null=True)
    snapshot_refs = SnapshotModelField(
        ['tests.Example', ['ExampleReference', {'fields': ['name', 'ref'], 'refs': ['ref']}]]
    )


obj = Example.objects.create(name='test_name')
obj_ref = ExampleReference.objects.create(name='refname', ref=obj)

snap = ExampleSnapshotModel.objects.create(snapshot=obj, snapshot_refs=obj_ref)

assert snap.snapshot.name == obj.name
assert snap.snapshot_refs.name == obj_ref.name
assert snap.snapshot_refs.ref.name == obj.name

obj.delete()
obj_ref.delete()
snap.refresh_from_db()

assert snap.snapshot.name == obj.name
assert snap.snapshot_refs.name == obj_ref.name
assert snap.snapshot_refs.ref.name == obj.name
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Apkawa/django-snapshot-field",
    "name": "django-snapshot-field",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "django",
    "author": "Apkawa",
    "author_email": "apkawa@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/d0/e8/4f8cb81e303e4125bdb0da7e2f75cc3b2eb17c9bd894fe7c59d5efd355cb/django_snapshot_field-0.1.5.tar.gz",
    "platform": null,
    "description": "[![ci](https://github.com/Apkawa/django-snapshot-field/actions/workflows/ci.yml/badge.svg)](https://github.com/Apkawa/django-snapshot-field/actions/workflows/ci.yml)\n\n[![PyPi](https://img.shields.io/pypi/v/django-snapshot-field.svg)](https://pypi.python.org/pypi/django-snapshot-field)\n[![PyPI](https://img.shields.io/pypi/pyversions/django-snapshot-field.svg)](https://pypi.python.org/pypi/django-snapshot-field)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)\n\nA field in a model that stores a snapshot of a model object and retrieves it as a read-only model object\n\n# Installation\n\n```bash\npip install django-snapshot-field\n```\n\nor from git\n\n```bash\npip install -e git+https://githib.com/Apkawa/django-snapshot-field.git#egg=django-snapshot-field\n```\n\n## Django and python version compatibles\n\n\n| Python<br/>Django | 3.8 | 3.9 | 3.10 | 3.11 | 3.12 | 3.13 |\n|:-----------------:|-----|----|------|------|------|------|\n|        4.2        | \u2705   | \u2705  | \u2705    | \u2705    | \u2705    | \u2705    |\n|        5.0        | \u274c   | \u274c   | \u2705    | \u2705    | \u2705    | \u2705    |\n|        5.1        | \u274c   | \u274c   | \u2705    | \u2705    | \u2705    | \u2705    |\n|        5.2        | \u274c   | \u274c   | \u2705    | \u2705    | \u2705    | \u2705    |\n\n\n\n# Usage\n\n```python\nfrom django.db import models\nfrom snapshot_field.fields import SnapshotModelField\n\nclass Example(models.Model):\n    name = models.CharField(max_length=20)\n\nclass ExampleReference(models.Model):\n    name = models.CharField(max_length=20)\n    ref = models.ForeignKey(Example)\n\n\nclass ExampleSnapshotModel(models.Model):\n    snapshot = SnapshotModelField(null=True)\n    snapshot_refs = SnapshotModelField(\n        ['tests.Example', ['ExampleReference', {'fields': ['name', 'ref'], 'refs': ['ref']}]]\n    )\n\n\nobj = Example.objects.create(name='test_name')\nobj_ref = ExampleReference.objects.create(name='refname', ref=obj)\n\nsnap = ExampleSnapshotModel.objects.create(snapshot=obj, snapshot_refs=obj_ref)\n\nassert snap.snapshot.name == obj.name\nassert snap.snapshot_refs.name == obj_ref.name\nassert snap.snapshot_refs.ref.name == obj.name\n\nobj.delete()\nobj_ref.delete()\nsnap.refresh_from_db()\n\nassert snap.snapshot.name == obj.name\nassert snap.snapshot_refs.name == obj_ref.name\nassert snap.snapshot_refs.ref.name == obj.name\n```\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A field in a model that store a snapshot of a model object and retrieves it as a read-only model object",
    "version": "0.1.5",
    "project_urls": {
        "Homepage": "https://github.com/Apkawa/django-snapshot-field"
    },
    "split_keywords": [
        "django"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "af3fd88d5527a6cabac3ddb7995a27555111eaa7fa5fd6318d80bfe343fd04ba",
                "md5": "cb3e58fbe9af5b8c06f4e5893a0002f4",
                "sha256": "f26c6ac099ab67a2eb0447ad3da1a26c982bc0b87682e079ac508decf1f0967a"
            },
            "downloads": -1,
            "filename": "django_snapshot_field-0.1.5-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "cb3e58fbe9af5b8c06f4e5893a0002f4",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 8572,
            "upload_time": "2025-01-11T06:50:20",
            "upload_time_iso_8601": "2025-01-11T06:50:20.286669Z",
            "url": "https://files.pythonhosted.org/packages/af/3f/d88d5527a6cabac3ddb7995a27555111eaa7fa5fd6318d80bfe343fd04ba/django_snapshot_field-0.1.5-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d0e84f8cb81e303e4125bdb0da7e2f75cc3b2eb17c9bd894fe7c59d5efd355cb",
                "md5": "af97f02166bbbe44557a3edc793544ca",
                "sha256": "41bbf02f88dd37c09cd1f60eae40071e91ed3e7f944881d4c79d847cb387cd7c"
            },
            "downloads": -1,
            "filename": "django_snapshot_field-0.1.5.tar.gz",
            "has_sig": false,
            "md5_digest": "af97f02166bbbe44557a3edc793544ca",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 9252,
            "upload_time": "2025-01-11T06:50:22",
            "upload_time_iso_8601": "2025-01-11T06:50:22.642126Z",
            "url": "https://files.pythonhosted.org/packages/d0/e8/4f8cb81e303e4125bdb0da7e2f75cc3b2eb17c9bd894fe7c59d5efd355cb/django_snapshot_field-0.1.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-11 06:50:22",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Apkawa",
    "github_project": "django-snapshot-field",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "tox": true,
    "lcname": "django-snapshot-field"
}
        
Elapsed time: 1.42891s