from django.contrib import admin

from .models import Gkno
from .models import NumberCardForVote
from .models import TuFar
from .models import Zayavka
from .models import VidVbr
from .models import Vbr
from .models import VidRibol
from .models import Vodoem
from .models import TipVodoem
from .models import Okopof
from .models import Zagot
from .models import UchAuction
from .models import UchItogAuction
from .models import KvotaBassein
from .models import KvotaOsvoenie
from .models import SravnenieProshlProcent
from .models import SravnenieProshlTonn
from .models import AuctionLot
from .models import ItogAuctionLot
from .models import NumberAuctionLot

from import_export.admin import ImportExportModelAdmin
from .resources import GknoResource
from .resources import NumberCardForVoteResource
from .resources import TuFarResource
from .resources import ZayavkaResource
from .resources import VidVbrResource
from .resources import VbrResource
from .resources import VidRibolResource
from .resources import VodoemResource
from .resources import TipVodoemResource
from .resources import OkopofResource
from .resources import ZagotResource
from .resources import UchAuctionResource
from .resources import UchItogAuctionResource
from .resources import KvotaBasseinResource
from .resources import KvotaOsvoenieResource
from .resources import SravnenieProshlProcentResource
from .resources import SravnenieProshlTonnResource
from .resources import AuctionLotResource
from .resources import ItogAuctionLotResource
from .resources import NumberAuctionLotResource

# Следующий импорт для сортировки в админке
from django.contrib.admin import AdminSite
from django.contrib.auth.models import Group, User
from django.contrib.auth.admin import GroupAdmin, UserAdmin


# НАЧАЛО Данный блок для сортировки пунктов в админке в рамках одного приложения

class MyAdminSite(AdminSite):

    def get_app_list(self, request):
        """
        Return a sorted list of all the installed apps that have been
        registered in this site.
        """
        app_dict = self._build_app_dict(request)

        # Sort the apps alphabetically.
        ##############################app_list = sorted(app_dict.values(), key=lambda x: x['name'].lower())

        # Sort the models alphabetically within each app.
        #for app in app_list:
        #    app['models'].sort(key=lambda x: x['name'])

        ###############################return app_list
        # Разделение моделей на группы
        grouped_app_dict = {'Group 1': {}, 'Group 2': {}}
        for app_label, app_data in app_dict.items():
            # Разделение моделей по вашему критерию
            if app_label == 'far':
                for model, model_dict in app_data['models'].items():
                    if model.startswith('Gk'):
                        grouped_app_dict['Group 1'][model] = model_dict
                    elif model.startswith('Num'):
                        grouped_app_dict['Group 2'][model] = model_dict
            else:
                # Добавление остальных моделей в группу "Other"
                grouped_app_dict.setdefault('Other', {})['models'].update(app_data['models'])

        return grouped_app_dict

# КОНЕЦ сртировки в админке
admin.site = MyAdminSite()

admin.site.register(Group, GroupAdmin)
admin.site.register(User, UserAdmin) почемувозникает ошибка Internal Server Error: /admin/
Traceback (most recent call last):
  File "C:\WEB\far_django_on_blog\venv\Lib\site-packages\django\core\handlers\exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "C:\WEB\far_django_on_blog\venv\Lib\site-packages\django\core\handlers\base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\WEB\far_django_on_blog\venv\Lib\site-packages\django\contrib\admin\sites.py", line 261, in wrapper
    return self.admin_view(view, cacheable)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\WEB\far_django_on_blog\venv\Lib\site-packages\django\utils\decorators.py", line 134, in _wrapper_view
    response = view_func(request, *args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\WEB\far_django_on_blog\venv\Lib\site-packages\django\views\decorators\cache.py", line 62, in _wrapper_view_func
    response = view_func(request, *args, **kwargs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\WEB\far_django_on_blog\venv\Lib\site-packages\django\contrib\admin\sites.py", line 242, in inner
    return view(request, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\WEB\far_django_on_blog\venv\Lib\site-packages\django\contrib\admin\sites.py", line 552, in index
    app_list = self.get_app_list(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\WEB\far_django_on_blog\far\admin.py", line 83, in get_app_list
    grouped_app_dict.setdefault('Other', {})['models'].update(app_data['models'])
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
KeyError: 'models'
[12/Aug/2023 14:37:18] "GET /admin/ HTTP/1.1" 500 101325
 как исправить