Primary Authors
@wesleykendall (Wes Kendall)
History tracking for Django and Postgres
django-pghistory provides automated and customizable history tracking for Django models using Postgres triggers. Users can configure a number of event trackers to snapshot every model change or to fire specific events when certain changes occur in the database.
In contrast with other Django auditing and history tracking apps (seen here), django-pghistory has the following advantages:
No instrumentation of model and queryset methods in order to properly track history. After configuring your model, events will be tracked automatically with no other changes to code. In contrast with apps like django-reversion, it is impossible for code to accidentally bypass history tracking, and users do not have to use a specific model/queryset interface to ensure history is correctly tracked.
Bulk updates and all other modifications to the database that do not fire Django signals will still be properly tracked.
Historical event modeling is completely controlled by the user and kept in sync with models being tracked. There are no cumbersome generic foreign keys and little dependence on unstructured JSON fields for tracking changes, making it easier to use the historical events in your application (and in a performant manner).
Changes to multiple objects in a request (or any level of granularity) can be grouped together under the same context. Although history tracking happens in Postgres triggers, application code can still attach metadata to historical events, such as the URL of the request, leading to a more clear and useful audit trail.
To get started, read the django-pghistory docs. The docs covers how to set up and configure automated event tracking in your application, along with how to aggregate events for objects and visualize them in your admin/application.
Install django-pghistory with:
pip3 install django-pghistory
After this, add pghistory to the INSTALLED_APPS setting of your Django project.
pghistory uses django-pgtrigger and django-pgconnection as dependencies. Although these are automatically installed, the user needs to add pgtrigger and pgconnection to settings.INSTALLED_APPS, along with properly setting up django-pgconnection in settings.py as follows:
import pgconnection DATABASES = pgconnection.configure({ 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': 'mydatabase', } })
For information on setting up django-pghistory for development and contributing changes, view CONTRIBUTING.rst.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Details for the file django-pghistory-1.0.1.tar.gz
.
Algorithm | Hash digest | |
---|---|---|
SHA256 | c92dc4fe14e8b7179b3ae4ec183b6b28a3bbec11eb950039ef2c55c0ff1e4dbb |
|
MD5 | ad73deea234f7499d94c074e21965100 |
|
BLAKE2b-256 | c30fb0feec85fc6c3c6fc3d9ffd831d33af6b30d0dd1915a0b68258ef4af4269 |
Details for the file django_pghistory-1.0.1-py3-none-any.whl
.
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a38db7cb6d2e3e34eac078bf442196c8470ce1a3e28d31ec3f6d7a2bd3de2ed |
|
MD5 | 791c3cc1bcc961baa73f8b4e3cc11830 |
|
BLAKE2b-256 | 39c2732136dcd218bd2442adaaa8e00397202978e9e674fb9e012202fe447dce |