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.
pip install django-auditlogVerified import paths — ran on the pinned version, not inferred.
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.
Ensure your project uses Python 3.10 or newer (Python 3.10 is the minimum requirement for django-auditlog v3.4.0+).
Upgrade your Django project to Django 4.2 or newer. Django 4.2 is the minimum requirement for django-auditlog v3.0.0+.
Be aware that historical log entries will now persist even if their original object's PK is reused. This is generally a safer default, preventing unintended data loss in audit trails.
If experiencing issues with actor tracking in complex or asynchronous environments on Django 4.2+, review your custom context handling or ensure `AuditlogMiddleware` is correctly in place.
Always include `auditlog.middleware.AuditlogMiddleware` in your Django `MIDDLEWARE` settings. For custom scenarios (e.g., management commands or Celery tasks), use `auditlog.context.set_actor(user)` manually.
If you plan to use `AUDITLOG_STORE_JSON_CHANGES = True`, ensure you are on version `3.3.0` or newer for full stability and correct `changes_display_dict` behavior.