-
Notifications
You must be signed in to change notification settings - Fork 66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom admin site for reordering app list #2421
Changes from 1 commit
ae827bb
383b8d6
4d84788
7d26195
72f121e
b9570bf
c49e00c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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: | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Этот метод не использует состояние класс, поэтому его лучше оформить как There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Тут же вроде dict, не? |
||||||
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") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Мне хотелось бы видеть это в отдельном ПР, если у тебя есть время на это. Здесь мы работаем над списком приложений в админке