Model instance change logging for django models.
Project description
Django Delta Logger
A django app that provides a model class that records changes in django models.
Installation
Get the Package
pip install django_delta_logger
Update the Django Settings
Add django_delta_logger
to the INSTALLED_APPS
list.
INSTALLED_APPS=[
# ...
'django_delta_logger',
# ...
]
Make sure JSON_ENCODER
is set in the django settings. A reasonable default is provided and is directly importable into an existing settings file.
from django_delta_logger.settings import JSON_ENCODER
Usage
Django_delta_logger's primary API is a context manager:
from django_delta_logger.delta_logger import DeltaLogger
with DeltaLogger(SomeDjangoModel, SomeOtherDjangoModel):
foo = SomeDjangoModel(name='foo')
foo.save()
Log Results
Access the history of a model instance from the DeltaEvent
model.
from django_delta_logger.models import DeltaEvent
instance = SomeModel.objects.get(pk=1)
events = DeltaEvent.objects.get_for_instance(instance).all()
for event in events:
print(event.event_time, event.event_type, event.event_data)
from django_delta_logger.models import DeltaEvent
events = DeltaEvent.objects.get_for_model(SomeDjangoModel).all()
for event in events:
print(event.event_time, event.event_type, event.event_data)
The Risks of Concurrency
Tracking the dirtyness
of a model instance field is performant but can lead to inaccurate log data when one
model instance is edited in multiple threads/processes/servers.
When data accuracy in a concurrent environment is worth the performance cost of a fetch-before-write:
from django_delta_logger.delta_logger import DeltaLogger
with DeltaLogger(SomeDjangoModel, concurrent=True):
foo = SomeDjangoModel(name='foo')
foo.save()
Test Suite
python setup.py test
License
This software is published under the MIT License. See the LICENSE
file
for details.
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
Hashes for django_delta_logger-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c39e93c325b146b17bf1adbe61e7bc3255a6e99062847e7279358d460857509 |
|
MD5 | 6b87db6da3a7773832912f92e96c39c7 |
|
BLAKE2b-256 | 65f6738ef464c761a834db5df826056699d9aaee43c4ed92ee40af34f5c94b7e |
Hashes for django_delta_logger-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e57ff017292c7566f70810f2de389aee91b467ce33dec6c622ee0b51d5b88e48 |
|
MD5 | 991c4be69974d82527594483c1d7d555 |
|
BLAKE2b-256 | 15c30a658bf4934ca11ab162929f0e2f478bcf5ca302c0f9ccab5996218e894a |