Skip to main content

Model audit trails

Project description

django-audimatic

Coverage Status

Easy audit trails.

Installation

pip install django-audimatic

# or

pipenv install django-audimatic

# or

# install with your manager of choice

Usage

  1. Add to INSTALLED_APPS

    INSTALLED_APPS = [
        ...,
        "django_audimatic",
        ...
    ]
    
  2. Create audit trail tables and subclass AuditTrigger

    from django.contrib.auth.models import AbstractUser
    from django_audimatic.models import AuditTrail, AuditTrigger
    
    
    class UserAuditTrail(AuditTrail):
        pass
    
    
    class CustomUser(AbstractUser, AuditTrigger):
        class Meta(AuditTrigger.Meta):
            audit_table = UserAuditTrail
    
  3. Register AdminModels

    from django.contrib import admin
    from django.contrib.auth.admin import UserAdmin
    
    from django_audimatic.admin import DiffInline
    from testapp.models import CustomUser, UserAuditTrail
    
    
    class CustomUserAuditTrail(DiffInline):
        model = CustomUser.get_audit_table()
    
    
    class CustomUserAdmin(UserAdmin):
        inlines = (CustomUserAuditTrail,)
    
    
    admin.site.register(UserAuditTrail, admin.ModelAdmin)
    admin.site.register(CustomUser, CustomUserAdmin)
    
  4. Add HStoreExtension

    from django.contrib.postgres.operations import HStoreExtension
    
    ...
        operations = [
            HStoreExtension(),
        ]
    ...
    

Other

This project uses django-pgtrigger and django-nonrelated-inlines.

Currently, (as of Django 4.2.4) there is logic that registers these automatically, this might break in future version of Django.

There is functionality to disable migration support in pgtrigger, however that is not recommended or tested.

Inlines will always be registered as well, this is for simplicity, but maybe we add some options in the future.

License

Copyright 2023 Bill Schumacher

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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_audimatic-0.3.1.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

django_audimatic-0.3.1-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file django_audimatic-0.3.1.tar.gz.

File metadata

  • Download URL: django_audimatic-0.3.1.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for django_audimatic-0.3.1.tar.gz
Algorithm Hash digest
SHA256 75b9a4e945b3611ce512f764d1b9663efc66152e1f7fe7a0d6991404193d2321
MD5 f2f80c24508e615cc84e6780fa46e667
BLAKE2b-256 65d4ccf37877138736e8438dc33e1a480aafbf5c8b8c1dfc65133ac4b0610f32

See more details on using hashes here.

File details

Details for the file django_audimatic-0.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_audimatic-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5675fc76eb4fdac22f1c52d66ad0b9ee1d1a2f084a2e2d42cd143d7b2f237b46
MD5 780ece862e5b93537643ff04303a223c
BLAKE2b-256 54ff1061f9ce3779159ccbed29cfdcf4c54afcf2ca8eff47c7cadb215a0fffde

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page