Skip to main content

Management command and middleware for Django history triggers.

Project description

django-history-triggers

django-history-triggers is a Django application for installing database triggers that automatically record inserts, updates, and deletes to model tables.

Requirements

  • Django 3.0+
  • PostgreSQL or SQLite database

Installation

pip install django-history-triggers

Quick Start

  1. Add history to your INSTALLED_APPS setting and migrate your database.
  2. Add history.middleware.HistoryMiddleware to the end of your MIDDLEWARE setting.
  3. Run manage.py triggers enable to install the trigger functions, or manage.py triggers disable to uninstall them. Neither will clear existing history data -- add a --clear option to do that.

Settings

  • HISTORY_MODEL (default: "history.ObjectHistory")
  • HISTORY_IGNORE_APPS (default: ["admin", "contenttypes", "sessions"])
  • HISTORY_MIDDLEWARE_IGNORE (default: [])
  • HISTORY_REQUEST_CONTEXT (default: "history.get_request_context")
  • HISTORY_ADMIN_ENABLED (default: True)

History Sessions

History is recorded within "sessions" that you can manage manually, either outside of a web request context, or in place of or in addition to the included middleware. The easiest way to manage a history session is via a context manager:

from history import get_backend

def api_view(request):
    # You can pass extra fields to be stored for all history within a session.
    with get_backend().session(user=request.user, path=request.path):
        # All history inside here will have the same session_id and session_date.
        ...

Custom History Model

The default history.ObjectHistory model is swappable by changing the HISTORY_MODEL setting. If you need to define your own object history model (usually for tracking custom fields or non-standard user info), be sure to inherit from history.models.AbstractObjectHistory. If at all possible, do this early on to avoid problems with migrations when changing HISTORY_MODEL after the initial migration.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_history_triggers-3.0.1-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file django_history_triggers-3.0.1-py3-none-any.whl.

File metadata

  • Download URL: django_history_triggers-3.0.1-py3-none-any.whl
  • Upload date:
  • Size: 15.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.27.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.8

File hashes

Hashes for django_history_triggers-3.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 58269c7f3862742340164d9715eecb26306b030e4ae356703e8121f2b6ab43fa
MD5 14dd8f1029bbc549d7fc643dc3047cfe
BLAKE2b-256 747c71e1b5805c80bd928a6ba866655562e38c3167e7a27ad4f843c3012444a0

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