Django Audit Log

3.4.1 · active · verified Sun Apr 12

django-auditlog is a pluggable Django app that provides audit logging functionality for your models. It automatically tracks changes to model instances (create, update, delete actions), recording who made the change, when, and what changed. The current version is 3.4.1, and the project maintains an active release cadence with frequent updates to support new Django and Python versions.

Warnings

Install

Imports

Quickstart

To get started with django-auditlog: 1. Add 'auditlog' to your `INSTALLED_APPS` in `settings.py`. 2. Add 'auditlog.middleware.AuditlogMiddleware' to your `MIDDLEWARE` list in `settings.py` (essential for 'actor' tracking). 3. Run `python manage.py makemigrations` and `python manage.py migrate` to create the `LogEntry` table. 4. Place the provided code snippet in your app's `models.py` (or similar location) to register `MyAuditedModel`. Once set up, any creates, updates, or deletes on `MyAuditedModel` instances will automatically generate `LogEntry` records. You can then query `LogEntry.objects` or use the Django Admin to view the audit trail.

from django.db import models
from auditlog.registry import auditlog

class MyAuditedModel(models.Model):
    name = models.CharField(max_length=255)
    description = models.TextField(blank=True)
    
    def __str__(self):
        return self.name

    class Meta:
        app_label = 'myapp' # Replace 'myapp' with your actual app name

# Register the model for audit logging
auditlog.register(MyAuditedModel)

view raw JSON →