Skip to main content

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


Download files

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

Source Distribution

djang-frozen-data-0.1a1.tar.gz (5.2 kB view hashes)

Uploaded Source

Built Distribution

djang_frozen_data-0.1a1-py3-none-any.whl (6.0 kB view hashes)

Uploaded Python 3

Supported by

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