make deactivaton safe

even if apps were not loaded rigth
This commit is contained in:
Matthias 2021-11-17 01:51:05 +01:00
parent 8708279629
commit 3d2648ffb2
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076

View File

@ -269,12 +269,17 @@ class PluginAppConfig(AppConfig):
for plugin_path in settings.INTEGRATION_APPS_PATHS: for plugin_path in settings.INTEGRATION_APPS_PATHS:
models = [] # the modelrefs need to be collected as poping an item in a iter is not welcomed models = [] # the modelrefs need to be collected as poping an item in a iter is not welcomed
app_name = plugin_path.split('.')[-1] app_name = plugin_path.split('.')[-1]
try:
app_config = apps.get_app_config(app_name)
# check all models # check all models
for model in apps.get_app_config(app_name).get_models(): for model in app_config.get_models():
# remove model from admin site # remove model from admin site
admin.site.unregister(model) admin.site.unregister(model)
models += [model._meta.model_name] models += [model._meta.model_name]
except LookupError:
# if an error occurs the app was never loaded right -> so nothing to do anymore
break
# unregister the models (yes, models are just kept in multilevel dicts) # unregister the models (yes, models are just kept in multilevel dicts)
for model in models: for model in models: