From 456b17eb8b452c8b3601c1d55b45aef8a962e22d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20Ferrat=C3=A9?= Date: Wed, 15 May 2024 16:28:31 +0200 Subject: [PATCH] Disabled admin interface from settings.py --- auditlog/admin.py | 6 +++++- auditlog/conf.py | 5 +++++ docs/source/usage.rst | 7 +++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/auditlog/admin.py b/auditlog/admin.py index 130f480..fa0ece9 100644 --- a/auditlog/admin.py +++ b/auditlog/admin.py @@ -1,5 +1,6 @@ from functools import cached_property +from django.conf import settings from django.contrib import admin from django.contrib.auth import get_user_model from django.utils.translation import gettext_lazy as _ @@ -9,7 +10,6 @@ from auditlog.mixins import LogEntryAdminMixin from auditlog.models import LogEntry -@admin.register(LogEntry) class LogEntryAdmin(admin.ModelAdmin, LogEntryAdminMixin): list_select_related = ["content_type", "actor"] list_display = [ @@ -57,3 +57,7 @@ class LogEntryAdmin(admin.ModelAdmin, LogEntryAdminMixin): def get_queryset(self, request): self.request = request return super().get_queryset(request=request) + + +if not settings.AUDITLOG_DISABLE_ADMIN_INTERFACE: + admin.site.register(LogEntry, LogEntryAdmin) diff --git a/auditlog/conf.py b/auditlog/conf.py index dbdfc5b..c465747 100644 --- a/auditlog/conf.py +++ b/auditlog/conf.py @@ -26,6 +26,11 @@ settings.AUDITLOG_DISABLE_ON_RAW_SAVE = getattr( settings, "AUDITLOG_DISABLE_ON_RAW_SAVE", False ) +# Disable django admin interface +settings.AUDITLOG_DISABLE_ADMIN_INTERFACE = getattr( + settings, "AUDITLOG_DISABLE_ADMIN_INTERFACE", False +) + # CID settings.AUDITLOG_CID_HEADER = getattr( diff --git a/docs/source/usage.rst b/docs/source/usage.rst index 8cabfbf..40cb560 100644 --- a/docs/source/usage.rst +++ b/docs/source/usage.rst @@ -463,3 +463,10 @@ Django Admin integration When ``auditlog`` is added to your ``INSTALLED_APPS`` setting a customized admin class is active providing an enhanced Django Admin interface for log entries. + + +If you want to not register the django admin interface, you can set the following setting: + +.. code-block:: python + + AUDITLOG_DISABLE_ADMIN_INTERFACE = True