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 | RSS feed

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.

Source Distribution

django-auditor-1.00.tar.gz (5.4 kB view details)

Uploaded Source

File details

Details for the file django-auditor-1.00.tar.gz.

File metadata

  • Download URL: django-auditor-1.00.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for django-auditor-1.00.tar.gz
Algorithm Hash digest
SHA256 9deac6e1a0f789027074bb2f1f1b88c4904b210b6f22120d2bf52a318d5b769b
MD5 b17d66984afffd29a68a6ea71745efcd
BLAKE2b-256 a09d5cecf4e72cac74f5927ee3e4158300ae0fb4aca332f587aaf58c82617026

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