from django.apps import apps as _apps
from django.contrib import admin
from django.contrib.admin.sites import AlreadyRegistered

from .models import *
from admin_ordering.admin import OrderableAdmin

# Register your models here.


@admin.register(Button)
class ButtonModelAdmin(OrderableAdmin, admin.ModelAdmin):
    list_display = ['__str__', 'published', 'ordering']
    list_editable = ['ordering']
    ordering_field_hide_input = True
    exclude = ['ordering']


@admin.register(UpperButton)
class UpperButtonModelAdmin(OrderableAdmin, admin.ModelAdmin):
    list_display = ['__str__', 'published', 'ordering']
    list_editable = ['ordering']
    ordering_field_hide_input = True
    exclude = ['ordering']


apps = [
    'main',
    'administration',
    'league',
    'calendar',
    'gpb',
    'tournaments',
    'membership',
    'youth',
    'atu',
    'mbkb',
    'core'
]

for app in [app for name, app in _apps.app_configs.items() if name in apps]:
    app_models = app.get_models()
    for model in app_models:
        try:
            admin.site.register(model)
        except AlreadyRegistered:
            pass


admin.site.site_header = 'pdlzbs'
admin.site.site_title = 'pdlzbs'
admin.site.index_title = 'Panel administracyjny'
admin.site.site_url = '/'
admin.site.enable_nav_sidebar = False
