unresgister models when deactivating

This commit is contained in:
Matthias 2021-11-15 01:01:55 +01:00
parent 65ff226b90
commit 87edbf7c33
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076

View File

@ -207,6 +207,14 @@ class PluginAppConfig(AppConfig):
return plugin_path
def deactivate_integration_app(self):
# unregister models from admin
for app_name in settings.INTEGRATION_APPS_PATHS:
for model in apps.get_app_config(app_name.split('.')[-1]).get_models():
try:
admin.site.unregister(model)
except:
pass
# remove plugin from installed_apps
for plugin in settings.INTEGRATION_APPS_PATHS:
settings.INSTALLED_APPS.remove(plugin)