Add model fields to track creation and modification dates, users and more on save
Project description
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.
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 Distribution
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_audit_fields-2.0.6.tar.gz.
File metadata
- Download URL: django_audit_fields-2.0.6.tar.gz
- Upload date:
- Size: 21.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d593794cf04330eb50358359f83a5e949b32a6506ebe8d40a6b4a91de27c8b0
|
|
| MD5 |
e34d968f7ab0a0ee4dd836df46fb70d5
|
|
| BLAKE2b-256 |
cc879049f6fe034ad28ab25badf3b835dbaed9c67f8e87ff655219f1f5acc41f
|
File details
Details for the file django_audit_fields-2.0.6-py3-none-any.whl.
File metadata
- Download URL: django_audit_fields-2.0.6-py3-none-any.whl
- Upload date:
- Size: 26.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ece5579c0395186e8b111494c99c9a6738adfd884f85d86bc4fc13fa950e37f0
|
|
| MD5 |
4d475335d81ea046a04f37cee737ec26
|
|
| BLAKE2b-256 |
13f2ed3346026e4df0db18fd38220640ea828423dce4490e30b6b92cf5227cdb
|