Skip to content

Commit

Permalink
Add ability to globally exclude fields by name on all models
Browse files Browse the repository at this point in the history
  • Loading branch information
darkpixel committed Jan 18, 2023
1 parent f6b9e9f commit b7895bb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions auditlog/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions auditlog/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
17 changes: 17 additions & 0 deletions docs/source/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit b7895bb

Please sign in to comment.