Skip to main content

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

  1. Install using pip:

  2. Add 'model_logger' to your INSTALLED_APPS in settings.py:

  3. 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 action
  • description: Detailed description of the action
  • timestamp: When the action occurred
  • content_type: The model type being logged
  • object_id: The specific object's ID
  • content_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.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. 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

Acknowledgments

  • Thanks to the Django community for inspiration
  • All the contributors who participate in this project

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_logging_easy-0.2.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_logging_easy-0.2-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

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

Hashes for django_logging_easy-0.2.tar.gz
Algorithm Hash digest
SHA256 a68f30a4928ec27e46955ea1b0610119172cce2933156a56eeb509792230f916
MD5 35510f42c6b08a46ed8ea5884aaa01c6
BLAKE2b-256 99d77098cf072eec5135fd168a01c70f48bde2583512a068a2baaaee9f339c64

See more details on using hashes here.

File details

Details for the file django_logging_easy-0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_logging_easy-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 0c6650bdddf2f144b10f4dad6984c99c96e16a8e8b50a4a0ffc3d993d4a9747e
MD5 87a52bda6d46858186ebcb9fad03d1e2
BLAKE2b-256 52f3d0a9c3cc5e4b796285c0c1e8545502f805fb932ef797b511eeb95b226392

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page