Browse Source

Remove duplicate code from generic admin setup

pull/6/head
Marcio Mazza 10 years ago
parent
commit
78d343cb76
  1. 11
      base/admin.py
  2. 11
      comissoes/admin.py
  3. 11
      lexml/admin.py
  4. 11
      materia/admin.py
  5. 11
      norma/admin.py
  6. 11
      parlamentares/admin.py
  7. 11
      protocoloadm/admin.py
  8. 13
      sapl/utils.py
  9. 11
      sessao/admin.py

11
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__)

11
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__)

11
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__)

11
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__)

11
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__)

11
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__)

11
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__)

13
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)

11
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__)

Loading…
Cancel
Save