Skip to main content

A Django app for advanced logging capabilities

Project description

Django Tracker

Django Tracker is a middleware for Django that automatically audits and logs all model changes made through user requests. It records the user responsible, the fields changed, and other useful information for tracking data changes.

Installation

pip install django-tracker-unergy

Setup

  1. Add 'django_tracker' to INSTALLED_APPS in your settings.py:
INSTALLED_APPS = [
    # ...
    'django_tracker',
]

and add the middleware

MIDDLEWARE = [
    # ...
    'django_tracker.middleware.CurrentUserMiddleware'
]
  1. Run migrations:
python manage.py makemigrations
python manage.py migrate django_tracker

Usage

Auditable Decorator

from django_tracker.decorators import auditable

@auditable(
    tracked_fields=['field1', 'field2'],
    exclude_fiels=["created_at", "updated_at"]
    audit_creates=True,
    audit_updates=True,
    audit_deletes=True,
    level=AuditLevel.MEDIUM
)
class MyModel(models.Model):
    field1 = models.CharField(max_length=100)
    field2 = models.IntegerField()
    # And the control attrb

Querying Audit Logs

You can view audit logs in the Django admin or directly from the model:

from django_tracker.models import AuditLog

# Get changes for a specific object
logs = AuditLog.objects.filter(
    content_type__model='mymodel',
    object_id=obj_id
)

# Get changes by user
logs = AuditLog.objects.filter(username='username')

License

MIT License. See LICENSE file for details.

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_tracker_unergy-1.0.3.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

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

django_tracker_unergy-1.0.3-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file django_tracker_unergy-1.0.3.tar.gz.

File metadata

  • Download URL: django_tracker_unergy-1.0.3.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.13

File hashes

Hashes for django_tracker_unergy-1.0.3.tar.gz
Algorithm Hash digest
SHA256 7f9bada7922384575714bd1d502c2ffe14d15b141ace5d0d321bef9c5ad17ee8
MD5 93637d6a8a5eb33ab6b57ef77a9d97e3
BLAKE2b-256 26405a833f93d616104ba638c39e944b69ea6aaad5a7b795150d76e69a6641c4

See more details on using hashes here.

File details

Details for the file django_tracker_unergy-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for django_tracker_unergy-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 18a73b33a19a747614e355080aaf6d581258ed26ccf11af14c8e30b3a56cba77
MD5 83d5e1540fe20a8c6779a7e6e3a42c75
BLAKE2b-256 8bdde109dc021225f0273a0221f156cc5f39982e8fc1ee39a66edd5b8e8a1686

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