From 9c7d0de96584e21ba7d0696fca7cb7060972b1f7 Mon Sep 17 00:00:00 2001 From: Fabian Braun Date: Mon, 4 Nov 2024 14:09:52 +0100 Subject: [PATCH] fix: Do not initialize `REGISTERED_ADMINS` with model setting --- djangocms_link/admin.py | 2 +- djangocms_link/apps.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/djangocms_link/admin.py b/djangocms_link/admin.py index c9af5f3f..559ad4b9 100644 --- a/djangocms_link/admin.py +++ b/djangocms_link/admin.py @@ -25,7 +25,7 @@ class GrouperModelAdmin: pass -REGISTERED_ADMIN = getattr(settings, "DJANGOCMS_LINKABLE_MODELS", "auto") +REGISTERED_ADMIN = [] # Will be set by djangocms_link.apps.DjangoCmsLinkConfig.ready class AdminUrlsView(BaseListView): diff --git a/djangocms_link/apps.py b/djangocms_link/apps.py index 9e248e81..f1b12fa4 100644 --- a/djangocms_link/apps.py +++ b/djangocms_link/apps.py @@ -1,4 +1,5 @@ from django.apps import AppConfig, apps +from django.conf import settings from django.contrib.admin import ModelAdmin from django.core.exceptions import ImproperlyConfigured from django.utils.translation import gettext_lazy as _ @@ -14,7 +15,9 @@ def ready(self): from djangocms_link import admin as link_admin - if link_admin.REGISTERED_ADMIN == "auto": # pragma: no cover + link_model_setting = getattr(settings, "DJANGOCMS_LINKABLE_MODELS", "auto") + + if link_model_setting == "auto": # pragma: no cover # Autoconfig? Check the admin registry for suitable admins link_admin.REGISTERED_ADMIN = [] for _admin in admin.site._registry.values(): @@ -28,7 +31,7 @@ def ready(self): else: # turn model config into model admin instances admins = [] - for model in link_admin.REGISTERED_ADMIN: + for model in link_model_setting: if isinstance(model, str): model = apps.get_model(model) if not hasattr(model, "get_absolute_url"): # pragma: no cover