A Django app to log model changes
Project description
Django Model Logger
A simple and flexible Django app for logging model actions and changes. This package allows developers to easily add logging capabilities to their Django models using decorators.
Features
- 🚀 Easy to integrate with existing Django projects
- 🎯 Generic relations to work with any model
- 📝 Customizable log names and descriptions
- ⏰ Automatic timestamp tracking
- 🔍 Simple log retrieval
- 🎨 Clean and intuitive API
Installation
-
Install using pip:
-
Add 'model_logger' to your INSTALLED_APPS in settings.py:
-
Run migrations:
Usage
Basic Usage
Retrieving Logs
from django.contrib.contenttypes.models import ContentType
from model_logger.models import ModelLog
# Get all logs for a specific article
article = Article.objects.get(id=1)
logs = ModelLog.objects.filter(
content_type=ContentType.objects.get_for_model(Article),
object_id=article.id
)
# Get all logs across all models
all_logs = ModelLog.objects.all()
ModelLog Fields
The ModelLog model includes the following fields:
name: The name of the logged actiondescription: Detailed description of the actiontimestamp: When the action occurredcontent_type: The model type being loggedobject_id: The specific object's IDcontent_object: Generic foreign key to the logged object
Advanced Usage
Custom Log Names and Descriptions
class Article(models.Model):
title = models.CharField(max_length=100)
@log_action(
name="Article Published",
description="Article was published to the main page"
)
def publish(self):
self.is_published = True
self.save()
Dynamic Descriptions
class Article(models.Model):
title = models.CharField(max_length=100)
@log_action(
name="Title Change",
description="Title changed from '{old_title}' to '{new_title}'"
)
def update_title(self, new_title):
old_title = self.title
self.title = new_title
self.save()
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Requirements
- Python 3.6+
- Django 3.2+
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
If you encounter any problems or have suggestions, please open an issue on GitHub.
Authors
- Hasan Furkan - Initial work - hasan-furkan
Acknowledgments
- Thanks to the Django community for inspiration
- All the contributors who participate in this project
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_logging_easy-0.2.tar.gz.
File metadata
- Download URL: django_logging_easy-0.2.tar.gz
- Upload date:
- Size: 4.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a68f30a4928ec27e46955ea1b0610119172cce2933156a56eeb509792230f916
|
|
| MD5 |
35510f42c6b08a46ed8ea5884aaa01c6
|
|
| BLAKE2b-256 |
99d77098cf072eec5135fd168a01c70f48bde2583512a068a2baaaee9f339c64
|
File details
Details for the file django_logging_easy-0.2-py3-none-any.whl.
File metadata
- Download URL: django_logging_easy-0.2-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c6650bdddf2f144b10f4dad6984c99c96e16a8e8b50a4a0ffc3d993d4a9747e
|
|
| MD5 |
87a52bda6d46858186ebcb9fad03d1e2
|
|
| BLAKE2b-256 |
52f3d0a9c3cc5e4b796285c0c1e8545502f805fb932ef797b511eeb95b226392
|