Simple audit for model instances in Django.
Project description
This applications was created to audit model’s changes and maintain a log of them
Installation
You can install django-simple-audit in 2 ways: using pip or by setup.py install
$ pip install django-simple-audit
Then modify your settings.py, adding the package simple_audit in INSTALLED_APPS and in MIDDLEWARE_CLASSES add simple_audit.middleware.TrackingRequestOnThreadLocalMiddleware:
INSTALLED_APPS = (
'...',
'simple_audit',
)
MIDDLEWARE_CLASSES = (
'...',
'simple_audit.middleware.TrackingRequestOnThreadLocalMiddleware',
)
Usage
Tracking changes on a model
to audit a model you need import simple_audit and then register the model to be audited.
from django.db import models
import simple_audit
class Message(models.Model):
title = models.CharField(max_length=50, blank=False)
text = models.TextField(blank=False)
def __unicode__(self):
return self.text
class Owner(models.Model):
name = models.CharField(max_length=50, blank=False)
def __unicode__(self):
return self.name
class VirtualMachine(models.Model):
name = models.CharField(max_length=50, blank=False)
cpus = models.IntegerField()
owner = models.ForeignKey(Owner)
so = models.CharField(max_length=100, blank=False)
started = models.BooleanField()
def __unicode__(self):
return self.name
simple_audit.register(Message, Owner, VirtualMachine)
Advanced Usage (without httprequest or our middleware)
You can use django-simple-audit without an http request (for example in management command). In this situation there is no http request on thread context. To ensure gathering all modification on a single AuditRequest, you can specify it:
AuditRequest.new_request(path, user, ip)
try:
# my code... in same thread
finally:
AuditRequest.cleanup_request()
Tracking m2m fields changes
Tracking m2m fields changes is still experimental, but you can enable it with the following variable:
DJANGO_SIMPLE_AUDIT_M2M_FIELDS = True
Dependencies
Django >= 1.4.x
django.contrib.contenttypes installed in INSTALLED_APPS
TODO
Improve tests
CHANGELOG
- 0.1.12
Created some simple tests
Enable many to many fiedls tracking (see Usage)
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
Hashes for django-simple-audit-0.1.12b.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c4fc5a55d2f2e432ca48b7748ed983260eb03679613673dfc7d80597fcdc2d6 |
|
MD5 | 48691ad54a333b163dfbbedfa2ebeac4 |
|
BLAKE2b-256 | b22c9f313ba3392b4ecf782b4a2ac7a722943b2c3d9ca7eadb4e644403c4bd5f |