Skip to main content

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

Project description

ci

PyPi PyPI License

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

Installation

pip install django-snapshot-field

or from git

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

Django and python version compatibles

Python
Django
3.8 3.9 3.10 3.11 3.12 3.13
4.2
5.0
5.1
5.2

Usage

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_snapshot_field-0.1.5.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_snapshot_field-0.1.5-py2.py3-none-any.whl (8.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file django_snapshot_field-0.1.5.tar.gz.

File metadata

  • Download URL: django_snapshot_field-0.1.5.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.21

File hashes

Hashes for django_snapshot_field-0.1.5.tar.gz
Algorithm Hash digest
SHA256 41bbf02f88dd37c09cd1f60eae40071e91ed3e7f944881d4c79d847cb387cd7c
MD5 af97f02166bbbe44557a3edc793544ca
BLAKE2b-256 d0e84f8cb81e303e4125bdb0da7e2f75cc3b2eb17c9bd894fe7c59d5efd355cb

See more details on using hashes here.

File details

Details for the file django_snapshot_field-0.1.5-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_snapshot_field-0.1.5-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f26c6ac099ab67a2eb0447ad3da1a26c982bc0b87682e079ac508decf1f0967a
MD5 cb3e58fbe9af5b8c06f4e5893a0002f4
BLAKE2b-256 af3fd88d5527a6cabac3ddb7995a27555111eaa7fa5fd6318d80bfe343fd04ba

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page