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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_delta_logger-0.1.1.tar.gz.
File metadata
- Download URL: django_delta_logger-0.1.1.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.5.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
45cfedc680a9fecdbf2c71293c25635ddc27ca461bbcb08c174959bdb78cf89a
|
|
| MD5 |
6d679be0b096fe727b4a015a3c0e89f4
|
|
| BLAKE2b-256 |
a4f1d650e8de597f5fe0f5034fb7ae89951e2c38c850c34a04a64112dadc2799
|
File details
Details for the file django_delta_logger-0.1.1-py3-none-any.whl.
File metadata
- Download URL: django_delta_logger-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.5.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce14c750ce50cd141b0dc22403835e7f3f7b5f6d51ab91fc066586df203b33cb
|
|
| MD5 |
6a15f1ad1f5a72d8da1ace50f8965f02
|
|
| BLAKE2b-256 |
55cd616eca825d492de8b8a7a202c390241b515aea626da0ec941350e914a619
|