django-audit-fields


Namedjango-audit-fields JSON
Version 2.0.0 PyPI version JSON
download
home_pageNone
SummaryAdd model fields to track creation and modification dates, users and more on save
upload_time2025-08-18 00:51:53
maintainerErik van Widenfelt
docs_urlNone
authorErik van Widenfelt
requires_python>=3.12
licenseNone
keywords django clinicedc edc clinical trials research data management esource
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            |pypi| |actions| |codecov| |downloads| |clinicedc|


django-audit-fields
===================

`django-audit-fields.readthedocs.io <https://django-audit-fields.readthedocs.io/>`_

DJ5.2+, py3.12+

Important:
    * As of version 2.0.0, `edc-utils`_ is no longer a dependency of ``django-audit-fields``.


This module includes `django-revision`_ and is best used together with `django-simple-history`_.

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
------------

.. code-block:: bash

    pip install django-audit-fields

Add ``django-audit-fields`` to INSTALLED_APPS

.. code-block:: python

    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``

.. code-block:: python

    from django_audit_fields.model_mixins 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``

.. code-block:: python

    from django_audit_fields.model_mixins 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 <https://django-revision.readthedocs.io/>`_.


.. |pypi| image:: https://img.shields.io/pypi/v/django-audit-fields.svg
   :target: https://pypi.python.org/pypi/django-audit-fields

.. |codecov| image:: https://codecov.io/gh/erikvw/django-audit-fields/branch/develop/graph/badge.svg
   :target: https://codecov.io/gh/erikvw/django-audit-fields

.. |downloads| image:: https://pepy.tech/badge/django-audit-fields
   :target: https://pepy.tech/project/django-audit-fields

.. |actions| image:: https://github.com/erikvw/django-audit-fields/actions/workflows/build.yml/badge.svg
   :target: https://github.com/erikvw/django-audit-fields/actions/workflows/build.yml

.. |clinicedc| image:: https://img.shields.io/badge/framework-Clinic_EDC-green
   :alt:Made with clinicedc
   :target: https://github.com/clinicedc

.. _django-revision: https://github.com/erikvw/django-revision
.. _edc-utils: https://github.com/clinicedc/edc-utils
.. _django-simple-history: https://github.com/django-commons/django-simple-history

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "django-audit-fields",
    "maintainer": "Erik van Widenfelt",
    "docs_url": null,
    "requires_python": ">=3.12",
    "maintainer_email": "Erik van Widenfelt <ew2789@gmail.com>",
    "keywords": "django, clinicedc, edc, clinical trials, research, data management, esource",
    "author": "Erik van Widenfelt",
    "author_email": "Erik van Widenfelt <ew2789@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/0e/50/b96b201403b8199d73c7e96d796dfb66fc8deeb40afbd6059112e4d9bb07/django_audit_fields-2.0.0.tar.gz",
    "platform": null,
    "description": "|pypi| |actions| |codecov| |downloads| |clinicedc|\n\n\ndjango-audit-fields\n===================\n\n`django-audit-fields.readthedocs.io <https://django-audit-fields.readthedocs.io/>`_\n\nDJ5.2+, py3.12+\n\nImportant:\n    * As of version 2.0.0, `edc-utils`_ is no longer a dependency of ``django-audit-fields``.\n\n\nThis module includes `django-revision`_ and is best used together with `django-simple-history`_.\n\nOlder versions\n--------------\n* <=0.3.3 (DJ 3.1, py 3.7, 3.8)\n* >=0.3.4 (DJ 3.2+, py 3.9+)\n* >=0.3.14 (DJ4.2, py3.11) includes locale\n\n\nInstallation\n------------\n\n.. code-block:: bash\n\n    pip install django-audit-fields\n\nAdd ``django-audit-fields`` to INSTALLED_APPS\n\n.. code-block:: python\n\n    INSTALLED_APPS = [\n        \"...\",\n        \"django_audit_fields.apps.AppConfig\",\n        \"...\"]\n\nUsage\n-----\n\nAdd model fields to track creation and modification dates, users and more on save.\n\n\nDeclare your model using ``AuditModelMixin``\n\n.. code-block:: python\n\n    from django_audit_fields.model_mixins import AuditModelMixin\n    from simple_history.models import HistoricalRecords\n\n    class MyModel(AuditModelMixin,  models.Model):\n\n        history = HistoricalRecord()\n\n        class Meta(AuditModelMixin.Meta):\n            pass\n\nPreferably, use a UUID as primary key by declaring your model using ``AuditUuidModelMixin``\n\n.. code-block:: python\n\n    from django_audit_fields.model_mixins import AuditUuidModelMixin\n    from simple_history.models import HistoricalRecords\n\n    class MyModel(AuditUuidModelMixin, models.Model):\n\n        history = HistoricalRecord()\n\n        class Meta(AuditUuidModelMixin.Meta):\n            pass\n\n\nModel mixins ``AuditModelMixin`` and ``AuditUuidModelMixin``\n------------------------------------------------------------\n\nThe model mixin ``AuditUuidModelMixin`` sets the ``id`` fields to a ``UUIDField`` instead of an integer field.\n\nModel mixins ``AuditModelMixin`` and ``AuditUuidModelMixin`` add audit fields:\n\n+-------------------+-----------------+----------------------------+\n| Field             | Field class     | Update event               |\n+===================+=================+============================+\n| created           | DateTimeField   | only set on pre-save add   |\n+-------------------+-----------------+----------------------------+\n| modified          | DateTimeField   | updates on every save      |\n+-------------------+-----------------+----------------------------+\n| user_created      | CharField       | only set on pre-save add   |\n+-------------------+-----------------+----------------------------+\n| user_modified     | CharField       | updates on every save      |\n+-------------------+-----------------+----------------------------+\n| hostname_created  | CharField       | only set on pre-save add   |\n+-------------------+-----------------+----------------------------+\n| hostname_modified | CharField       | updates on every save      |\n+-------------------+-----------------+----------------------------+\n| locale_created    | CharField       | only set on pre-save add   |\n+-------------------+-----------------+----------------------------+\n| locale_modified   | CharField       | updates on every save      |\n+-------------------+-----------------+----------------------------+\n| revision          | RevisionField*  | updates on every save      |\n+-------------------+-----------------+----------------------------+\n\n\n* RevisionField is from django-revision. See `django-revision.readthedocs.io <https://django-revision.readthedocs.io/>`_.\n\n\n.. |pypi| image:: https://img.shields.io/pypi/v/django-audit-fields.svg\n   :target: https://pypi.python.org/pypi/django-audit-fields\n\n.. |codecov| image:: https://codecov.io/gh/erikvw/django-audit-fields/branch/develop/graph/badge.svg\n   :target: https://codecov.io/gh/erikvw/django-audit-fields\n\n.. |downloads| image:: https://pepy.tech/badge/django-audit-fields\n   :target: https://pepy.tech/project/django-audit-fields\n\n.. |actions| image:: https://github.com/erikvw/django-audit-fields/actions/workflows/build.yml/badge.svg\n   :target: https://github.com/erikvw/django-audit-fields/actions/workflows/build.yml\n\n.. |clinicedc| image:: https://img.shields.io/badge/framework-Clinic_EDC-green\n   :alt:Made with clinicedc\n   :target: https://github.com/clinicedc\n\n.. _django-revision: https://github.com/erikvw/django-revision\n.. _edc-utils: https://github.com/clinicedc/edc-utils\n.. _django-simple-history: https://github.com/django-commons/django-simple-history\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Add model fields to track creation and modification dates, users and more on save",
    "version": "2.0.0",
    "project_urls": {
        "Changelog": "https://github.com/erikvw/django-audit-fields/blob/main/CHANGES",
        "Documentation": "https://github.com/erikvw/django-audit-fields/docs",
        "Homepage": "https://github.com/erikvw/django-audit-fields",
        "Repository": "https://github.com/erikvw/django-audit-fields.git"
    },
    "split_keywords": [
        "django",
        " clinicedc",
        " edc",
        " clinical trials",
        " research",
        " data management",
        " esource"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "4532fa979f58fafc581a4761a7be0a810d0b8dfb530a39ae0306be233aefe1eb",
                "md5": "9d6ea3815be133ea125613d62626e792",
                "sha256": "f3d5c524e3b017739c3fd6329e01d3181fce6ef87cabeca76f50e4c2050a9623"
            },
            "downloads": -1,
            "filename": "django_audit_fields-2.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9d6ea3815be133ea125613d62626e792",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.12",
            "size": 28895,
            "upload_time": "2025-08-18T00:51:52",
            "upload_time_iso_8601": "2025-08-18T00:51:52.415522Z",
            "url": "https://files.pythonhosted.org/packages/45/32/fa979f58fafc581a4761a7be0a810d0b8dfb530a39ae0306be233aefe1eb/django_audit_fields-2.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "0e50b96b201403b8199d73c7e96d796dfb66fc8deeb40afbd6059112e4d9bb07",
                "md5": "71b2128f238e22441dd62eb37b0f5fdf",
                "sha256": "779449448da97a566239498f340e6d6239a33266798fbcaa19aa9ef0653033ce"
            },
            "downloads": -1,
            "filename": "django_audit_fields-2.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "71b2128f238e22441dd62eb37b0f5fdf",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.12",
            "size": 21704,
            "upload_time": "2025-08-18T00:51:53",
            "upload_time_iso_8601": "2025-08-18T00:51:53.721544Z",
            "url": "https://files.pythonhosted.org/packages/0e/50/b96b201403b8199d73c7e96d796dfb66fc8deeb40afbd6059112e4d9bb07/django_audit_fields-2.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-18 00:51:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "erikvw",
    "github_project": "django-audit-fields",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "django-audit-fields"
}
        
Elapsed time: 2.03011s