Skip to main content
Documentation Status https://badges.gitter.im/JoinChat.svg Latest Version Supported Python versions Download format

django-audit-log

Tracking changes to django models.

  • Model fields for keeping track of the user and session that created and modified a model instance.

  • Abstract model class with fields created_by and modified_by fields.

  • A model manager class that can automatically track changes made to a model in the database.

  • Support for Django 1.6 and 1.7, South migrations, Django 1.7 migrations and custom User classes.

  • Python 3 and 2.x support

The documentation can be found here

Tracking full model history on M2M relations is not supported yet. Version 0.3.0 onwards is tested with Django 1.6. It should work with older versions of Django, but may break things unexpectedly!

Quickstart Guide

Install it with pip from PyPi:

pip install django-audit-log

Add audit_log.middleware.UserLoggingMiddleware to your MIDDLEWARE_CLASSES:

MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'audit_log.middleware.UserLoggingMiddleware',
)

To just track who created or edited a model instance just make it inherit from AuthStampedModel:

from audit_log.models import AuthStampedModel

class WarehouseEntry(AuthStampedModel):
    product = models.ForeignKey(Product)
    quantity = models.DecimalField(max_digits = 10, decimal_places = 2)

This will add 4 fields to the WarehouseEntry model:

  • created_by - A foreign key to the user that created the model instance.

  • created_with_session_key - Stores the session key with which the model instance was first created.

  • modified_by - A foreign key to the user that last saved a model instance.

  • modified_with_session_key - Stores the session key with which the model instance was last saved.

If you want to track full model change history you need to attach an AuditLog manager to the model:

from django.db import models
from audit_log.models.fields import LastUserField
from audit_log.models.managers import AuditLog


class ProductCategory(models.Model):
    name = models.CharField(max_length=150, primary_key = True)
    description = models.TextField()

    audit_log = AuditLog()

class Product(models.Model):
    name = models.CharField(max_length = 150)
    description = models.TextField()
    price = models.DecimalField(max_digits = 10, decimal_places = 2)
    category = models.ForeignKey(ProductCategory)

    audit_log = AuditLog()

You can then query the audit log:

In [2]: Product.audit_log.all()
Out[2]: [<ProductAuditLogEntry: Product: My widget changed at 2011-02-25 06:04:29.292363>,
        <ProductAuditLogEntry: Product: My widget changed at 2011-02-25 06:04:24.898991>,
        <ProductAuditLogEntry: Product: My Gadget super changed at 2011-02-25 06:04:15.448934>,
        <ProductAuditLogEntry: Product: My Gadget changed at 2011-02-25 06:04:06.566589>,
        <ProductAuditLogEntry: Product: My Gadget created at 2011-02-25 06:03:57.751222>,
        <ProductAuditLogEntry: Product: My widget created at 2011-02-25 06:03:42.027220>]

The documentation can be found here

Note: This project was not maintained actively for a while. One of the reasons was that I wasn’t receiving email notifications from GitHub. The other reason: We were using it just on a couple of projects that were frozen to old versions of Django. If you need any help with the project you can contact me by email directly if I don’t respond to your GitHub issues. Feel free to nudge me over email if you have a patch for something. You can find my email in the AUTHORS file.

Metadata

Release files for django-audit-log2 0.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-audit-log2 0.8.0
File Size Uploaded
django-audit-log2-0.8.0.tar.gz 14.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-audit-log2 0.8.0
File Interpreter ABI Platform
django_audit_log2-0.8.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 33.9 kB

Release files / django-audit-log2-0.8.0.tar.gz

Download URL django-audit-log2-0.8.0.tar.gz
Size 14.8 kB
Tags Source
SHA-256 checksum
How to use checksums
8e368e84f1276c1975a9d932756ede3c7991846a200e4df4530aba60db5b7acb
BLAKE2b-256 checksum
How to use checksums
6e279ec98f09106ed1d38efe123cd7dc435188fe4073a429f8736c175123d98c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.0

Release files / django_audit_log2-0.8.0-py2.py3-none-any.whl

Download URL django_audit_log2-0.8.0-py2.py3-none-any.whl
Size 19.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
4aac2b2dc6bc8a1328f576bdcc031db1efae0621367903ca0d6f6e72d0952b15
BLAKE2b-256 checksum
How to use checksums
0f09b5adf261d6d3517e8350929bb0ac2f46d5a57825980020ba8f911d5e114a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.0

Release history Release notifications | RSS feed

This release

0.8.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page