django-auditor 1.0

Creator: codyrutscher

Last updated:

Add to Cart

Description:

djangoauditor 1.0

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()

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()

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

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

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.