diff --git a/auditlog/conf.py b/auditlog/conf.py index a56a165e..2050677a 100644 --- a/auditlog/conf.py +++ b/auditlog/conf.py @@ -16,6 +16,11 @@ settings, "AUDITLOG_INCLUDE_TRACKING_MODELS", () ) +# Exclude named fields across all models +settings.AUDITLOG_EXCLUDE_TRACKING_FIELDS = getattr( + settings, "AUDITLOG_EXCLUDE_TRACKING_FIELDS", () +) + # Disable on raw save to avoid logging imports and similar settings.AUDITLOG_DISABLE_ON_RAW_SAVE = getattr( settings, "AUDITLOG_DISABLE_ON_RAW_SAVE", False diff --git a/auditlog/registry.py b/auditlog/registry.py index 998105fd..8b74eb3a 100644 --- a/auditlog/registry.py +++ b/auditlog/registry.py @@ -113,6 +113,9 @@ def register( "set. Did you forget to set serialized_data to True?" ) + for fld in settings.AUDITLOG_EXCLUDE_TRACKING_FIELDS: + exclude_fields.append(fld) + def registrar(cls): """Register models for a given class.""" if not issubclass(cls, Model): diff --git a/docs/source/usage.rst b/docs/source/usage.rst index 4961be2d..36c16d27 100644 --- a/docs/source/usage.rst +++ b/docs/source/usage.rst @@ -189,6 +189,23 @@ You can use this setting to register all your models: .. versionadded:: 2.1.0 +**AUDITLOG_EXCLUDE_TRACKING_FIELDS** + +You can use this setting to exclude named fields from ALL models. +This is useful when lots of models share similar fields like +```created``` and ```modified``` and you want those excluded from +logging. +It will be considered when ``AUDITLOG_INCLUDE_ALL_MODELS`` is `True`. + +.. code-block:: python + + AUDITLOG_EXCLUDE_TRACKING_FIELDS = ( + "created", + "modified" + ) + +.. versionadded:: 2.2.3 + **AUDITLOG_EXCLUDE_TRACKING_MODELS** You can use this setting to exclude models in registration process.