Store model fields history
Project description
django-fields-history
A Django app that track history changes in model fields.
Important note: currently only one implementation of FieldsHistory
is supported and it's with django.contrib.postgres.fields.JSONField
which is JSONB
under the hood. So only postgresql as database is supported
Similar projects:
Main difference that those libraries keep track of changes, and this library tracks the history change.
Simple explanation:
from field_history.trackers import FieldsHistoryTracker
class SimpleModel(models.Model):
field = models.CharField(max_length=50)
field_history = FieldsHistoryTracker(fields=['field'])
obj = SimpleModel.objects.create(field='value')
assert not obj.get_field_history()
obj.field = "new_value"
obj.save()
assert obj.get_field_history()
assert obj.get_field_history()[0].value == "value"
QuickStart
Install django-fields-history
:
pip install django-fields-history
Add fields_history.postgres
to INSTALLED_APPS
(currently only
postgres implementation is supported):
INSTALLED_APPS = [
# rest of apps
"fields_history.postgres",
]
And add trackers to your models and specify fields to track:
from field_history.trackers import FieldsHistoryTracker
class YourModel(models.Model):
...
history_tracker = FieldsHistoryTracker(fields=["field1", "field2"])
And you are done.
Implementation
Every change of your fields field changes be tracked in
fields_history.models.FieldsHistory
in:
fields_history.postgres
-JSONB
postgres field
One object per save if tracked fields has been changed.
Credits
Basically this project is implemented based on django-field-history which itself used django-model-utils.
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
Built Distribution
Hashes for django-fields-history-0.1.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ae848435cfe764ad3df37313bf77fe9e1586b720b8dc2a4ed372060aeecdb5d7 |
|
MD5 | 1da44477a357b8de0112d0dc17240b2d |
|
BLAKE2b-256 | b35ca0d6ff8e03e19db11f83b34fbf7a58a7cfca0cd25bb2d90736cb30afb5bc |
Hashes for django_fields_history-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6e2f17446fd62c4d8ba53bf891ca008e82a242aba0821f0d5a39673f19d5f921 |
|
MD5 | 1aa9858d1707add65d770a090e0e2769 |
|
BLAKE2b-256 | 4762731b3295a24c68e15b9d9a8e1e320b0916e796eb7f6fb27a07f3541f88c5 |