mirror of
https://github.com/jazzband/django-auditlog.git
synced 2026-03-16 22:20:26 +00:00
|
|
||
|---|---|---|
| .. | ||
| demo | ||
| sample_project | ||
| manage.py | ||
| README.md | ||
| requirements.txt | ||
Django Auditlog Sample Project
This is a minimal Django project for testing and demonstrating django-auditlog during development.
It includes comprehensive models with various field types and relationships (ForeignKey, ManyToMany)
to showcase how Auditlog tracks changes across different scenarios.
Project Structure
This sample project includes the following models:
- Post: Blog post model with title, content, author, category, and tags
- Category: Category model for organizing posts
- Tag: Tag model for labeling posts with keywords
All models are registered for audit logging through the AUDITLOG_INCLUDE_TRACKING_MODELS setting.
Setup and Installation
1. Create Virtual Environment and Install Dependencies
# Create virtual environment
python -m venv venv
# Activate virtual environment
# Linux/Mac:
source venv/bin/activate
# Windows:
venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
2. Database Setup
# Run migrations
python manage.py migrate
# Load sample data
python manage.py loaddata initial_data
3. Create Superuser
python manage.py createsuperuser
4. Start Development Server
python manage.py runserver
Testing Auditlog Features
-
Access Admin Interface: Visit
http://127.0.0.1:8000/admin/and log in with your superuser credentials -
Edit Models: Try editing
Post,Category, andTagobjects:- Create new posts
- Edit existing post titles, content
- Change categories
- Add/remove tags
- Change authors
-
View Audit Logs:
- Navigate to
auditlog > Log entriesin the Django admin - Filter by content type to see logs for specific models
- View detailed change information for each modification
- Use the date hierarchy to find logs from specific time periods
- Navigate to
File Structure
sample_project/
├── demo/ # Demo application
│ ├── models.py # Post, Category, Tag models
│ ├── admin.py # Django admin configuration
│ ├── fixtures/ # Sample data
│ └── migrations/ # Database migrations
├── sample_project/ # Django project settings
│ └── settings.py # Includes Auditlog configuration
└── manage.py
Auditlog Configuration
The project demonstrates configuration via settings:
# In settings.py
AUDITLOG_INCLUDE_TRACKING_MODELS = (
{"model": "demo.Post", "m2m_fields": ["tags"]},
"demo.Category",
"demo.Tag",
)