Skip to main content

This Django app logs changes to models objects in a simple and granular way.

Project description

This Django app logs changes to models objects in a simple and granular way. This app supports multi-tenant environments which use django-tenant-schemas.

Requirements

Python 3.4

Django 1.8

Installation (for environments without django-tenant-schemas)

Add “auditor” to your INSTALLED_APPS setting like this:

INSTALLED_APPS = (
    ...
    'django_auditor',
)

Add an empty dict ‘AUDITOR’ on your settings:

AUDITOR = {}

Include the auditor URLconf in your project urls.py like this:

url(r'^auditor/', include('django_auditor.urls'))

Run python manage.py makemigrations to create the migration file for auditor model.

Run python manage.py migrate to apply the migration and create the Auditor model.

Installation (django-tenant-schemas environments)

Add “auditor” to your SHARED_APPS or TENANT_APPS setting like this:

SHARED_APPS = (
    ...
    'django_auditor',
)

or

TENANT_APPS = (
    ...
    'django_auditor',
)

Add a dict ‘AUDITOR’ on your settings, specify a ‘tenant’ key with the value of your tenant model:

AUDITOR = {'tenant':'customers.Client'}

Include the auditor URLconf in your project urls.py like this:

url(r'^auditor/', include('django_auditor.urls'))

Run python manage.py makemigrations to create the migration file for auditor model.

Run python manage.py migrate_schemas to apply the migration and create the Auditor model.

Usage and Examples

Create an instance of Audit passing request and the object you want to log, then call the method create(), update() or delete() to generate a log with the appropriate action: CREATE, UPDATE or DELETE.

First you have to import the Audit class:

from django_auditor.auditor import Audit

New object

new_car = Car(name='Civic', manufacturer='Honda', color='Red')
new_car.save()
auditor = Audit(request, new_car).create()

Example Create

Update Object

change_car = Car.objects.get(name='Civic')
auditor = Audit(request, change_car)
change_car.name = 'City'
change_car.color = 'Yellow'
change_car.save()
auditor.update()

Example Update

Delete Object

remove_car = Car.objects.get(name='City')
auditor = Audit(request, remove_car)
remove_car.delete()
auditor.delete()

Example Delete

Now open http://yoursiteURL/auditor to check your logs.

Project details


Release history Release notifications

This version

1.0

Download files

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

Files for django-auditor, version 1.0
Filename, size File type Python version Upload date Hashes
Filename, size django-auditor-1.00.tar.gz (5.4 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page