Django model field used to store snapshot of data.
Project description
Django Frozen Data
Django model custom field for storing a frozen snapshot of an object.
Principles
- Behaves like a
ForeignKey
but the data is detached from the related object - Transparent to the client - it looks and behaves like the original object
- The frozen object cannot be resaved
- Supports nesting of objects
Usage
A frozen field can be declared like a ForeignKey
:
class Foo:
frozen_bar = FrozenObjectField(Bar, help_text="This is a frozen snapshot of the object.")
fresh_bar = ForeignKey(Bar, help_text="This is a live FK relationship.")
The field behaves exactly like a FK, with the exception that the object cannot be saved:
>>> bar = Bar()
>>> foo = Foo.objects.create(frozen_bar=bar, fresh_bar=bar)
>>> # the fresh field can be updated as you would expect
>>> foo.fresh_bar.save()
>>> # the frozen field cannot - to prevent overwriting new data.
>>> foo.frozen_bar.save()
>>> StaleObjectError: 'Object was frozen; defrosted objects cannot be saved.'
Issues - TODO
- Deserialization of DateField/DateTimeField values
- Deserialization of DecimalField values
- Deserialization of UUIDField values
- Deep object freezing
Running tests
The tests themselves use pytest
as the test runner. If you have installed the poetry
evironment, you can run them thus:
$ poetry run pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file djang-frozen-data-0.1a1.tar.gz
.
File metadata
- Download URL: djang-frozen-data-0.1a1.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.6 CPython/3.9.4 Darwin/20.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 07745cb4f316b5217725813373a49760951a5c716f36cf16a04ec9de7981a01b |
|
MD5 | 0e43d22b281d876c9cd4a0a2ed8c72b4 |
|
BLAKE2b-256 | 2668b5823f73e4a68ffb3bdaf27f820ca2f482e46d468f39281e227f24c1d20f |
File details
Details for the file djang_frozen_data-0.1a1-py3-none-any.whl
.
File metadata
- Download URL: djang_frozen_data-0.1a1-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.6 CPython/3.9.4 Darwin/20.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b43b1748fcddc229bac20f146e02cffe350369a14aa58ed69a135ffa9cf66dda |
|
MD5 | ad47b83370b93c9de769a28f33cf4fdc |
|
BLAKE2b-256 | f8db4ab298fe8a305a1d54b86026e48f23d188f967058cfd9ec010d2a01a84b8 |