【发布时间】:2019-10-06 09:59:18
【问题描述】:
默认情况下,Django 管理仪表板对我来说是这样的:
我想更改 Profile 部分中模型的顺序,因此通过使用 here 和 here 中的代码,我能够在 Django 管理仪表板中更改模型名称的顺序:
class MyAdminSite(admin.AdminSite):
def get_app_list(self, request):
"""
Return a sorted list of all the installed apps that have been
registered in this site.
"""
ordering = {
"Users": 1,
"Permissions": 2,
"Activities": 3,
}
app_dict = self._build_app_dict(request)
# a.sort(key=lambda x: b.index(x[0]))
# 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: ordering[x['name']])
return app_list
mysite = MyAdminSite()
admin.site = mysite
sites.site = mysite
新的外观和感觉:
但是如你所见,我丢失了AUTHENTICATION AND AUTHORIZATION 部分;我应该怎么做才能拥有所有部分,同时对Profile 部分有自己的自定义排序?
【问题讨论】:
标签: django