|
1 | 1 | from importlib import import_module |
2 | 2 |
|
3 | | -from django.apps.registry import apps |
| 3 | +from django.apps import apps |
4 | 4 | from django.conf import settings |
5 | | -from django.contrib.admin.models import LogEntry |
6 | 5 | from django.contrib.auth.models import Permission |
7 | 6 | from django.contrib.contenttypes.models import ContentType |
8 | 7 | from django.contrib.sessions.models import Session |
@@ -36,7 +35,13 @@ def get_model_list(class_list): |
36 | 35 | # By default, all but some models will be audited. |
37 | 36 | # The list of excluded models can be overwritten or extended |
38 | 37 | # 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 | + |
40 | 45 | UNREGISTERED_CLASSES = getattr(settings, 'DJANGO_EASY_AUDIT_UNREGISTERED_CLASSES_DEFAULT', UNREGISTERED_CLASSES) |
41 | 46 | UNREGISTERED_CLASSES.extend(getattr(settings, 'DJANGO_EASY_AUDIT_UNREGISTERED_CLASSES_EXTRA', [])) |
42 | 47 | get_model_list(UNREGISTERED_CLASSES) |
|
0 commit comments