Skip to main content

A Django model field for PostgreSQL to store changes to a model chronologically.

Project description


Provides an AuditHistory model field to store a chronological record of changes to a model (“audit history”) on the model. The historical record is stored in a designated JSON field, so no additional database tables are required.

Supports Django 1.11 (and possibly Django 2.x in the future) and PostgreSQL database backends.


Build Status


The basic principles are as follows:

  1. To enable this for a model, you make two changes:

    • add an AuditHistoryField named history to the model
    • add the AuditHistoryMixin to the model class
    • add your model to admin site, AuditHistoryAdmin)
  2. Then, instead of calling regular save() on the model after changing it, call save_with_audit_record() instead (passing in some meta data you want saved alongside, e.g. the event that caused the change, the user triggering it and some payload usually the set of modified fields.

  3. The history will appear in human-readable form in the admin.

That’s pretty much all there is to it.


Changes made to the model in the admin right now unfortunately do not contribute to the audit record.

Testapp setup and first steps

  1. Install Postgres locally (e.g. 10.x)
  2. Create local database audithistory, owned by user dev
  3. Create a virtualenv and activate: virtualenv venv, then source venv/bin/activate
  4. Install dependencies into virtualenv: pip install --requirement requirements.txt
  5. Run migrate
  6. Run createsuperuser
  7. Run runserver
  8. Create new model on http://localhost:8000/admin/test_app/blogpost/
  9. Edit model via http://localhost:8000/edit/1/
  10. Reload admin page and inspect history record

Run tests in local environment:

  • Run test (Ensure that user dev has rights to db creation alter user dev createdb;)

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-model-audit-history, version 1.1
Filename, size File type Python version Upload date Hashes
Filename, size django_model_audit_history-1.1-py2-none-any.whl (6.9 kB) File type Wheel Python version py2 Upload date Hashes View
Filename, size django-model-audit-history-1.1.tar.gz (5.9 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page