-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
383b8d6
commit 4d84788
Showing
2 changed files
with
16 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,26 @@ | ||
from typing import Any | ||
|
||
from django.contrib import admin | ||
from django.http.request import HttpRequest | ||
|
||
|
||
class AdminSite(admin.AdminSite): | ||
def __init__(self, name: str) -> None: | ||
super().__init__(name=name) | ||
self._registry.update(admin.site._registry) | ||
|
||
def get_app_list(self, request: Any, app_label: Any | None = None) -> list[Any]: | ||
def get_app_list(self, request: HttpRequest, app_label: str | None = None) -> list[str]: | ||
app_list = super().get_app_list(request, app_label) | ||
app_order = ["orders", "notion", "chains", "products", "otherapp"] | ||
app_list.sort(key=lambda x: app_order.index(x["app_label"]) if x["app_label"] in app_order else len(app_order)) | ||
app_list.sort(key=self._get_app_order_index) | ||
return app_list | ||
|
||
def _get_app_order_index(self, element: Any) -> int: | ||
app_order = ["orders", "notion", "chains", "products", "otherapp"] | ||
|
||
if element["app_label"] in app_order: | ||
return app_order.index(element["app_label"]) | ||
|
||
return len(app_order) | ||
|
||
|
||
admin_site = AdminSite(name="custom_admin") |