Skip to content

Commit 858403b

Browse files
committed
Import LogEntry only if admin is in INSTALLED_APPS
1 parent c27db1e commit 858403b

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

easyaudit/settings.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from importlib import import_module
22

3-
from django.apps.registry import apps
3+
from django.apps import apps
44
from django.conf import settings
5-
from django.contrib.admin.models import LogEntry
65
from django.contrib.auth.models import Permission
76
from django.contrib.contenttypes.models import ContentType
87
from django.contrib.sessions.models import Session
@@ -36,7 +35,13 @@ def get_model_list(class_list):
3635
# By default, all but some models will be audited.
3736
# The list of excluded models can be overwritten or extended
3837
# by defining the following settings in the project.
39-
UNREGISTERED_CLASSES = [CRUDEvent, LoginEvent, RequestEvent, Migration, LogEntry, Session, Permission, ContentType, MigrationRecorder.Migration]
38+
UNREGISTERED_CLASSES = [CRUDEvent, LoginEvent, RequestEvent, Migration, Session, Permission, ContentType, MigrationRecorder.Migration]
39+
40+
# Import and unregister LogEntry class only if Django Admin app is installed
41+
if apps.is_installed('django.contrib.admin'):
42+
from django.contrib.admin.models import LogEntry
43+
UNREGISTERED_CLASSES += [LogEntry]
44+
4045
UNREGISTERED_CLASSES = getattr(settings, 'DJANGO_EASY_AUDIT_UNREGISTERED_CLASSES_DEFAULT', UNREGISTERED_CLASSES)
4146
UNREGISTERED_CLASSES.extend(getattr(settings, 'DJANGO_EASY_AUDIT_UNREGISTERED_CLASSES_EXTRA', []))
4247
get_model_list(UNREGISTERED_CLASSES)

0 commit comments

Comments
 (0)