Skip to main content

History tracking for Django and Postgres

Project description

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:

  1. 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.

  2. Bulk updates and all other modifications to the database that do not fire Django signals will still be properly tracked.

  3. 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).

  4. 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.

Documentation

View the django-pghistory docs here.

Installation

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',
    }
})

Contributing Guide

For information on setting up django-pghistory for development and contributing changes, view CONTRIBUTING.rst.

Primary Authors

  • @wesleykendall (Wes Kendall)

Other Contributors

  • @shivananda-sahu

  • @asucrews

  • @Azurency

  • @dracos

  • @adamchainz

  • @eeriksp

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

django-pghistory-1.5.1.tar.gz (27.4 kB view details)

Uploaded Source

Built Distribution

django_pghistory-1.5.1-py3-none-any.whl (32.9 kB view details)

Uploaded Python 3

File details

Details for the file django-pghistory-1.5.1.tar.gz.

File metadata

  • Download URL: django-pghistory-1.5.1.tar.gz
  • Upload date:
  • Size: 27.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.10.1 Linux/5.13.0-1023-aws

File hashes

Hashes for django-pghistory-1.5.1.tar.gz
Algorithm Hash digest
SHA256 f6a89b50f5299965221a0e41b984dc01a04eb825c07a568dd0bb1bc2b66ed690
MD5 d1c3eaa44f10998e4883b14abec2ebd5
BLAKE2b-256 ec021af199f6b0c4c9791a5343d099dd05825b51375eee2ab3bf27a3f5e1be1d

See more details on using hashes here.

File details

Details for the file django_pghistory-1.5.1-py3-none-any.whl.

File metadata

  • Download URL: django_pghistory-1.5.1-py3-none-any.whl
  • Upload date:
  • Size: 32.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.10.1 Linux/5.13.0-1023-aws

File hashes

Hashes for django_pghistory-1.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 596dcd83475ae927c657fedd8e100de0ad8262e4fe4ef146ea3fdb03c99ca805
MD5 277295672f87e7e1bcf74a33d4c4e4ad
BLAKE2b-256 db7b42f30b8bd7c9bb38f3e2355de5d5b39d0ef189a3fb3e7423475c8d740577

See more details on using hashes here.

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