Skip to main content

django-auditkit

CI PyPI version Python 3.12+ Django 6.0+ License: MIT Code style: black

Reusable Django audit models with automatic timestamp tracking, user attribution, and optional soft-delete support. Includes admin mixins for seamless integration with Django Admin.

Features

  • 🔍 Full Audit Trail: Track created_at, updated_at, created_by, updated_by automatically
  • 🗑️ Soft Delete: Optional soft-delete with deleted_at and deleted_by tracking
  • 👤 User Attribution: Automatic tracking of who created/modified/deleted records
  • 🛡️ Safe Queries: Soft-deleted records excluded by default, with option to include them
  • 🔧 Admin Integration: Ready-to-use admin mixins with audit fields display
  • ⚡ QuerySet Optimizations: Built-in methods for common audit operations

Quick Start

Installation

pip install django-auditkit

Basic Usage

# models.py
from django.db import models
from auditkit.models import AuditModel

class MyModel(AuditModel):
    name = models.CharField(max_length=100)
    description = models.TextField()
    
    class Meta:
        ordering = ['-created_at']
# admin.py
from django.contrib import admin
from auditkit.admin import AuditAdminMixin
from .models import MyModel

@admin.register(MyModel)
class MyModelAdmin(AuditAdminMixin, admin.ModelAdmin):
    list_display = ('name', 'created_at', 'created_by', 'updated_at')
    list_filter = ('created_at', 'updated_at')
    search_fields = ('name', 'description')

Models

TimestampModel

Base model with automatic timestamp tracking.

from auditkit.models import TimestampModel

class Product(TimestampModel):
    name = models.CharField(max_length=100)
    price = models.DecimalField(max_digits=10, decimal_places=2)
    # Automatically gets:
    # - created_at: DateTimeField (auto_now_add)
    # - updated_at: DateTimeField (auto_now)

AuditModel

Full audit model with user attribution.

from auditkit.models import AuditModel

class Order(AuditModel):
    customer_name = models.CharField(max_length=100)
    total = models.DecimalField(max_digits=10, decimal_places=2)
    # Automatically gets:
    # - created_at, updated_at (from TimestampModel)
    # - created_by: ForeignKey to User
    # - updated_by: ForeignKey to User
    # - deleted_at: DateTimeField (null=True)
    # - deleted_by: ForeignKey to User (null=True)

Features:

  • Automatic population of created_by and updated_by on save
  • Soft delete support via delete() method
  • QuerySet excludes soft-deleted records by default

Soft Delete Operations

# Soft delete (sets deleted_at and deleted_by)
order = Order.objects.get(id=1)
order.delete()  # Soft delete - record still in DB

# Hard delete (permanent removal)
order.delete(hard=True)

# Restore soft-deleted record
order.restore()

# Query including soft-deleted records
all_orders = Order.objects.all_with_deleted()

# Query only soft-deleted records
deleted_orders = Order.objects.deleted()

# Check if record is soft-deleted
if order.is_deleted:
    print("This order was deleted")

Admin Mixins

AuditAdminMixin

Displays audit fields in Django Admin with proper formatting.

from django.contrib import admin
from auditkit.admin import AuditAdminMixin
from .models import Product

@admin.register(Product)
class ProductAdmin(AuditAdminMixin, admin.ModelAdmin):
    list_display = ('name', 'price', 'created_at', 'created_by')
    readonly_fields = ('created_at', 'updated_at', 'created_by', 'updated_by')

Features:

  • Automatically adds audit fields to readonly_fields
  • Displays timestamps in local timezone
  • Shows user links for created_by and updated_by

SoftDeleteAdminMixin

Adds soft-delete functionality to Django Admin.

from django.contrib import admin
from auditkit.admin import SoftDeleteAdminMixin
from .models import Order

@admin.register(Order)
class OrderAdmin(SoftDeleteAdminMixin, admin.ModelAdmin):
    list_display = ('customer_name', 'total', 'is_deleted', 'deleted_at')
    actions = ['soft_delete_selected', 'restore_selected']

Features:

  • Soft delete action for bulk operations
  • Restore action for recovering deleted records
  • Filter by deletion status

QuerySets and Managers

SoftDeleteQuerySet

Enhanced QuerySet with soft-delete awareness.

# Default: excludes soft-deleted records
active_orders = Order.objects.all()

# Include deleted
all_orders = Order.objects.all_with_deleted()

# Only deleted
deleted_orders = Order.objects.deleted()

# Restore multiple records
Order.objects.filter(id__in=[1, 2, 3]).restore()

# Hard delete multiple records
Order.objects.filter(id__in=[1, 2, 3]).delete(hard=True)

Configuration

Add auditkit to your INSTALLED_APPS:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    # ... other apps
    'auditkit',
    'myapp',
]

Requirements

  • Python 3.12+
  • Django 6.0+

License

MIT License - see LICENSE file for details.

Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

Important: All contributions must be made via Pull Request. Direct pushes to main or develop branches are not allowed.

Changelog

0.1.0 (2026-04-20)

  • Initial release
  • TimestampModel and AuditModel
  • Soft-delete support
  • Admin mixins
  • QuerySet optimizations

Metadata

Release files for django-auditkit 0.1.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-auditkit 0.1.0
File Size Uploaded Provenance Actions
django_auditkit-0.1.0.tar.gz 11.2 kB Without provenance Details for django_auditkit-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-auditkit 0.1.0
File Interpreter ABI Platform Actions
django_auditkit-0.1.0-py3-none-any.whl Python 3 none any Details for django_auditkit-0.1.0-py3-none-any.whl

Total release size: 19.6 kB

Release files / django_auditkit-0.1.0.tar.gz

Download URL django_auditkit-0.1.0.tar.gz
Size 11.2 kB
Tags Source
SHA-256 checksum
How to use checksums
4f5658327f9958d3f51c530950bc502221bbca06a1189c27a24ee2e298a7be7f
BLAKE2b-256 checksum
How to use checksums
40df7b18e2843a3f2e5c14f64cd4bfbd8438065069b99464ab68840399581037
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Release files / django_auditkit-0.1.0-py3-none-any.whl

Download URL django_auditkit-0.1.0-py3-none-any.whl
Size 8.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3ea96738a733830a6bc8629d7e29323a5a6303da82476e90588b992c04fef3fe
BLAKE2b-256 checksum
How to use checksums
86d2a6f658e861e9c18759618c89a30913169b6a25ba475bdb9bc46a265b8693
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Security for django-auditkit 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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