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
- Add
historyto your INSTALLED_APPS setting and migrate your database. - Add
history.middleware.HistoryMiddlewareto the end of yourMIDDLEWAREsetting. - Run
manage.py triggers enableto install the trigger functions, ormanage.py triggers disableto uninstall them. Neither will clear existing history data -- add a--clearoption 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58269c7f3862742340164d9715eecb26306b030e4ae356703e8121f2b6ab43fa
|
|
| MD5 |
14dd8f1029bbc549d7fc643dc3047cfe
|
|
| BLAKE2b-256 |
747c71e1b5805c80bd928a6ba866655562e38c3167e7a27ad4f843c3012444a0
|