On désactive l'interface admin en production, et on déplace la découverte des modèles dans shared

This commit is contained in:
Tom Hubrecht 2021-06-27 13:44:01 +02:00
parent 18383802d6
commit 6ba5a5c620
3 changed files with 17 additions and 13 deletions

View file

@ -1,12 +0,0 @@
from django.contrib import admin
from django.apps import apps
# FIXME: this is a temp workaround to help for development
models = apps.get_models()
for model in models:
try:
admin.site.register(model)
except admin.sites.AlreadyRegistered:
pass

View file

@ -6,7 +6,6 @@ from .views import HomeView
urlpatterns = [ urlpatterns = [
path("", HomeView.as_view(), name="kadenios"), path("", HomeView.as_view(), name="kadenios"),
path("admin/", admin.site.urls),
path("elections/", include("elections.urls")), path("elections/", include("elections.urls")),
path("faqs/", include("faqs.urls")), path("faqs/", include("faqs.urls")),
path("auth/", include("shared.auth.urls")), path("auth/", include("shared.auth.urls")),
@ -14,6 +13,11 @@ urlpatterns = [
path("i18n/", include("django.conf.urls.i18n")), path("i18n/", include("django.conf.urls.i18n")),
] ]
if settings.DEBUG:
urlpatterns += [
path("admin/", admin.site.urls),
]
if "debug_toolbar" in settings.INSTALLED_APPS: if "debug_toolbar" in settings.INSTALLED_APPS:
from debug_toolbar import urls as djdt_urls from debug_toolbar import urls as djdt_urls

12
shared/admin.py Normal file
View file

@ -0,0 +1,12 @@
from django.apps import apps
from django.conf import settings
from django.contrib import admin
if settings.DEBUG:
models = apps.get_models()
for model in models:
try:
admin.site.register(model)
except admin.sites.AlreadyRegistered:
pass