diff --git a/base/admin.py b/base/admin.py index 17d47f4c6..483f7357b 100644 --- a/base/admin.py +++ b/base/admin.py @@ -1,11 +1,4 @@ -from django.apps import apps -from django.contrib import admin +from sapl.utils import register_all_models_in_admin -appname = __name__.split('.')[0] -app = apps.get_app_config(appname) -for model in app.get_models(): - class CustomModelAdmin(admin.ModelAdmin): - list_display = [f.name for f in model._meta.fields if f.name != 'id'] - if not admin.site.is_registered(model): - admin.site.register(model, CustomModelAdmin) +register_all_models_in_admin(__name__) diff --git a/comissoes/admin.py b/comissoes/admin.py index 17d47f4c6..483f7357b 100644 --- a/comissoes/admin.py +++ b/comissoes/admin.py @@ -1,11 +1,4 @@ -from django.apps import apps -from django.contrib import admin +from sapl.utils import register_all_models_in_admin -appname = __name__.split('.')[0] -app = apps.get_app_config(appname) -for model in app.get_models(): - class CustomModelAdmin(admin.ModelAdmin): - list_display = [f.name for f in model._meta.fields if f.name != 'id'] - if not admin.site.is_registered(model): - admin.site.register(model, CustomModelAdmin) +register_all_models_in_admin(__name__) diff --git a/lexml/admin.py b/lexml/admin.py index 17d47f4c6..483f7357b 100644 --- a/lexml/admin.py +++ b/lexml/admin.py @@ -1,11 +1,4 @@ -from django.apps import apps -from django.contrib import admin +from sapl.utils import register_all_models_in_admin -appname = __name__.split('.')[0] -app = apps.get_app_config(appname) -for model in app.get_models(): - class CustomModelAdmin(admin.ModelAdmin): - list_display = [f.name for f in model._meta.fields if f.name != 'id'] - if not admin.site.is_registered(model): - admin.site.register(model, CustomModelAdmin) +register_all_models_in_admin(__name__) diff --git a/materia/admin.py b/materia/admin.py index 17d47f4c6..483f7357b 100644 --- a/materia/admin.py +++ b/materia/admin.py @@ -1,11 +1,4 @@ -from django.apps import apps -from django.contrib import admin +from sapl.utils import register_all_models_in_admin -appname = __name__.split('.')[0] -app = apps.get_app_config(appname) -for model in app.get_models(): - class CustomModelAdmin(admin.ModelAdmin): - list_display = [f.name for f in model._meta.fields if f.name != 'id'] - if not admin.site.is_registered(model): - admin.site.register(model, CustomModelAdmin) +register_all_models_in_admin(__name__) diff --git a/norma/admin.py b/norma/admin.py index 17d47f4c6..483f7357b 100644 --- a/norma/admin.py +++ b/norma/admin.py @@ -1,11 +1,4 @@ -from django.apps import apps -from django.contrib import admin +from sapl.utils import register_all_models_in_admin -appname = __name__.split('.')[0] -app = apps.get_app_config(appname) -for model in app.get_models(): - class CustomModelAdmin(admin.ModelAdmin): - list_display = [f.name for f in model._meta.fields if f.name != 'id'] - if not admin.site.is_registered(model): - admin.site.register(model, CustomModelAdmin) +register_all_models_in_admin(__name__) diff --git a/parlamentares/admin.py b/parlamentares/admin.py index 17d47f4c6..483f7357b 100644 --- a/parlamentares/admin.py +++ b/parlamentares/admin.py @@ -1,11 +1,4 @@ -from django.apps import apps -from django.contrib import admin +from sapl.utils import register_all_models_in_admin -appname = __name__.split('.')[0] -app = apps.get_app_config(appname) -for model in app.get_models(): - class CustomModelAdmin(admin.ModelAdmin): - list_display = [f.name for f in model._meta.fields if f.name != 'id'] - if not admin.site.is_registered(model): - admin.site.register(model, CustomModelAdmin) +register_all_models_in_admin(__name__) diff --git a/protocoloadm/admin.py b/protocoloadm/admin.py index 17d47f4c6..483f7357b 100644 --- a/protocoloadm/admin.py +++ b/protocoloadm/admin.py @@ -1,11 +1,4 @@ -from django.apps import apps -from django.contrib import admin +from sapl.utils import register_all_models_in_admin -appname = __name__.split('.')[0] -app = apps.get_app_config(appname) -for model in app.get_models(): - class CustomModelAdmin(admin.ModelAdmin): - list_display = [f.name for f in model._meta.fields if f.name != 'id'] - if not admin.site.is_registered(model): - admin.site.register(model, CustomModelAdmin) +register_all_models_in_admin(__name__) diff --git a/sapl/utils.py b/sapl/utils.py new file mode 100644 index 000000000..da019dfb9 --- /dev/null +++ b/sapl/utils.py @@ -0,0 +1,13 @@ +from django.apps import apps +from django.contrib import admin + + +def register_all_models_in_admin(module_name): + appname = module_name.split('.')[0] + app = apps.get_app_config(appname) + for model in app.get_models(): + class CustomModelAdmin(admin.ModelAdmin): + list_display = [f.name for f in model._meta.fields if f.name != 'id'] + + if not admin.site.is_registered(model): + admin.site.register(model, CustomModelAdmin) diff --git a/sessao/admin.py b/sessao/admin.py index 17d47f4c6..483f7357b 100644 --- a/sessao/admin.py +++ b/sessao/admin.py @@ -1,11 +1,4 @@ -from django.apps import apps -from django.contrib import admin +from sapl.utils import register_all_models_in_admin -appname = __name__.split('.')[0] -app = apps.get_app_config(appname) -for model in app.get_models(): - class CustomModelAdmin(admin.ModelAdmin): - list_display = [f.name for f in model._meta.fields if f.name != 'id'] - if not admin.site.is_registered(model): - admin.site.register(model, CustomModelAdmin) +register_all_models_in_admin(__name__)