django-audit-fields
This module has two model mixins that when used with a Django model adds a group of audit fields updated when a model instance is created and modified. This is one part of a strategy to be compliant with guidelines such as Good Clinical Practice (GCP), 21 CFR part 11, EU GDPR, UK GDPR, and the South African POPI Act. See the full list below of fields below.
This module includes django-revision, which tracks the source code revision, and is best used together with django-simple-history.
As of version 1.1.0, edc-utils is no longer a dependency of django-audit-fields.
Documentation: django-audit-fields.readthedocs.io
Requirements: DJ5.2+, py3.12+
Older versions
<=0.3.3 (DJ 3.1, py 3.7, 3.8)
>=0.3.4 (DJ 3.2+, py 3.9+)
>=0.3.14 (DJ4.2, py3.11) includes locale
Installation
pip install django-audit-fields
Add django-audit-fields to INSTALLED_APPS
INSTALLED_APPS = [
"...",
"django_audit_fields.apps.AppConfig",
"..."]
Usage
Add model fields to track creation and modification dates, users and more on save.
Declare your model using AuditModelMixin
from django_audit_fields.models import AuditModelMixin
from simple_history.models import HistoricalRecords
class MyModel(AuditModelMixin, models.Model):
history = HistoricalRecord()
class Meta(AuditModelMixin.Meta):
pass
Preferably, use a UUID as primary key by declaring your model using AuditUuidModelMixin
from django_audit_fields.models import AuditUuidModelMixin
from simple_history.models import HistoricalRecords
class MyModel(AuditUuidModelMixin, models.Model):
history = HistoricalRecord()
class Meta(AuditUuidModelMixin.Meta):
pass
Model mixins AuditModelMixin and AuditUuidModelMixin
The model mixin AuditUuidModelMixin sets the id fields to a UUIDField instead of an integer field.
Model mixins AuditModelMixin and AuditUuidModelMixin add audit fields:
Field |
Field class |
Update event |
|---|---|---|
created |
DateTimeField |
only set on pre-save add |
modified |
DateTimeField |
updates on every save |
user_created |
CharField |
only set on pre-save add |
user_modified |
CharField |
updates on every save |
hostname_created |
CharField |
only set on pre-save add |
hostname_modified |
CharField |
updates on every save |
locale_created |
CharField |
only set on pre-save add |
locale_modified |
CharField |
updates on every save |
revision |
RevisionField* |
updates on every save |
RevisionField is from django-revision. See django-revision.readthedocs.io.
Release files for django_audit_fields 2.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django_audit_fields-2.0.6.tar.gz | 21.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_audit_fields-2.0.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size:48.6 kB
Release files / django_audit_fields-2.0.6.tar.gz
| Download URL | django_audit_fields-2.0.6.tar.gz |
|---|---|
| Size | 21.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9d593794cf04330eb50358359f83a5e949b32a6506ebe8d40a6b4a91de27c8b0
|
|
BLAKE2b-256 checksum How to use checksums |
cc879049f6fe034ad28ab25badf3b835dbaed9c67f8e87ff655219f1f5acc41f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.8
|
Release files / django_audit_fields-2.0.6-py3-none-any.whl
| Download URL | django_audit_fields-2.0.6-py3-none-any.whl |
|---|---|
| Size | 26.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ece5579c0395186e8b111494c99c9a6738adfd884f85d86bc4fc13fa950e37f0
|
|
BLAKE2b-256 checksum How to use checksums |
13f2ed3346026e4df0db18fd38220640ea828423dce4490e30b6b92cf5227cdb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.8
|