django-audit-fields


Namedjango-audit-fields JSON
Version 0.3.16 PyPI version JSON
download
home_pagehttp://github.com/erikvw/django-audit-fields
SummaryAdd model fields to track creation and modification dates, users and more on save.
upload_time2024-02-11 16:11:42
maintainer
docs_urlNone
authorErik van Widenfelt
requires_python>=3.11
licenseGPL license, see LICENSE
keywords django edc audit field clinicedc clinical trials
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            |pypi| |actions| |codecov| |downloads|

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

VERSION
=======
* <=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 both ``django_audit_fields`` and ``django_revision`` to INSTALLED_APPS

.. code-block:: python

    INSTALLED_APPS = [
        "...",
        "django_revision.apps.AppConfig",
        "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

    class MyModel(AuditModelMixin,  models.Model):
        ...
        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

    class MyModel(AuditUuidModelMixin, models.Model):
        ...
        class Meta(AuditUuidModelMixin.Meta):
            pass

The model mixins ``AuditModelMixin`` and ``AuditUuidModelMixin``:

* add audit fields (created, modified, user_created, user_modified, hostname_created, hostname_modified);

The model mixin ``AuditUuidModelMixin`` also

* sets the id fields to a ``UUIDField`` instead of an integer;


Most models require an audit trail. If so, add the ``HistoricalRecord`` model manager from ``django-simple-history``:

.. code-block:: python

    from simple_history.models import HistoricalRecords

    class MyModel(AuditUuidModelMixin, models.Model):
        ...
        history = HistoricalRecords()

Notes
=====

User created and modified fields behave as follows:

* created is only set on pre-save add
* modified is always updated


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

            

Raw data

            {
    "_id": null,
    "home_page": "http://github.com/erikvw/django-audit-fields",
    "name": "django-audit-fields",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.11",
    "maintainer_email": "",
    "keywords": "django Edc audit field clinicedc,clinical trials",
    "author": "Erik van Widenfelt",
    "author_email": "ew2789@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/c2/47/368cc273fde74a802baaf7ece4dea7216a55e6d3040ee3559d50f7b659ca/django-audit-fields-0.3.16.tar.gz",
    "platform": null,
    "description": "|pypi| |actions| |codecov| |downloads|\n\ndjango-audit-fields\n-------------------\n\nVERSION\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\n\nAdd both ``django_audit_fields`` and ``django_revision`` to INSTALLED_APPS\n\n.. code-block:: python\n\n    INSTALLED_APPS = [\n        \"...\",\n        \"django_revision.apps.AppConfig\",\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\n    class MyModel(AuditModelMixin,  models.Model):\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\n    class MyModel(AuditUuidModelMixin, models.Model):\n        ...\n        class Meta(AuditUuidModelMixin.Meta):\n            pass\n\nThe model mixins ``AuditModelMixin`` and ``AuditUuidModelMixin``:\n\n* add audit fields (created, modified, user_created, user_modified, hostname_created, hostname_modified);\n\nThe model mixin ``AuditUuidModelMixin`` also\n\n* sets the id fields to a ``UUIDField`` instead of an integer;\n\n\nMost models require an audit trail. If so, add the ``HistoricalRecord`` model manager from ``django-simple-history``:\n\n.. code-block:: python\n\n    from simple_history.models import HistoricalRecords\n\n    class MyModel(AuditUuidModelMixin, models.Model):\n        ...\n        history = HistoricalRecords()\n\nNotes\n=====\n\nUser created and modified fields behave as follows:\n\n* created is only set on pre-save add\n* modified is always updated\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",
    "bugtrack_url": null,
    "license": "GPL license, see LICENSE",
    "summary": "Add model fields to track creation and modification dates, users and more on save.",
    "version": "0.3.16",
    "project_urls": {
        "Homepage": "http://github.com/erikvw/django-audit-fields"
    },
    "split_keywords": [
        "django edc audit field clinicedc",
        "clinical trials"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "43748fb1aa28f069645463bdb0e9f3f6e7dcdabe06ea354d9ce5e5ee2a78716a",
                "md5": "498ad39b716e5cb802c3a5f836167bb8",
                "sha256": "91c78f0d004139bfdf85cc29968bbea768c6083ee9d9ea53dd70574071cdaf58"
            },
            "downloads": -1,
            "filename": "django_audit_fields-0.3.16-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "498ad39b716e5cb802c3a5f836167bb8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.11",
            "size": 24167,
            "upload_time": "2024-02-11T16:11:40",
            "upload_time_iso_8601": "2024-02-11T16:11:40.288854Z",
            "url": "https://files.pythonhosted.org/packages/43/74/8fb1aa28f069645463bdb0e9f3f6e7dcdabe06ea354d9ce5e5ee2a78716a/django_audit_fields-0.3.16-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c247368cc273fde74a802baaf7ece4dea7216a55e6d3040ee3559d50f7b659ca",
                "md5": "9f4ed7708b719d3b017563607c35ac98",
                "sha256": "d90195f7f15426bc7437c0503ef01cb65db27d2a4beb655296bbc760240a4786"
            },
            "downloads": -1,
            "filename": "django-audit-fields-0.3.16.tar.gz",
            "has_sig": false,
            "md5_digest": "9f4ed7708b719d3b017563607c35ac98",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.11",
            "size": 25586,
            "upload_time": "2024-02-11T16:11:42",
            "upload_time_iso_8601": "2024-02-11T16:11:42.039449Z",
            "url": "https://files.pythonhosted.org/packages/c2/47/368cc273fde74a802baaf7ece4dea7216a55e6d3040ee3559d50f7b659ca/django-audit-fields-0.3.16.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-11 16:11:42",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "erikvw",
    "github_project": "django-audit-fields",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "lcname": "django-audit-fields"
}
        
Elapsed time: 0.33349s