订购admin.ModelAdmin对象 [英] Ordering admin.ModelAdmin objects
问题描述
比方说,我有我的披萨应用程序带有Topping和Pizza类,它们在Django Admin中显示如下:
Let's say I have my pizza application with Topping and Pizza classes and they show in Django Admin like this:
PizzaApp
-
Toppings >>>>>>>>>> Add / Change
Pizzas >>>>>>>>>> Add / Change
但我希望他们这样:
PizzaApp
-
Pizzas >>>>>>>>>> Add / Change
Toppings >>>>>>>>>> Add / Change
如何在admin.py中配置它?
How do I configure that in my admin.py?
推荐答案
以下是相关部分:
自定义管理索引页面
类似地,您可能希望b $ b自定义
Django admin索引页面的外观。
On a similar note, you might want to customize the look and feel of the Django admin index page.
默认情况下,它将在INSTALLED_APPS中显示所有具有$已在管理应用程序中注册的
,
按字母顺序排列。您可能希望
对
布局进行重大更改。毕竟,索引是
,可能是管理员
最重要的页面,并且应该易于
的使用。
By default, it displays all the apps in INSTALLED_APPS that have been registered with the admin application, in alphabetical order. You may want to make significant changes to the layout. After all, the index is probably the most important page of the admin, and it should be easy to use.
要自定义的模板是
admin / index.html。 (与前面
部分中的
admin / base_site.html相同–将其从默认
目录复制到自定义模板
目录中。)编辑文件,然后
会看到它使用了名为
app_list的模板变量。该变量包含每个
安装的Django应用。除了使用
之外,您还可以使用您认为最好的方式在
中硬编码链接到
对象特定的管理页面的链接。
The template to customize is admin/index.html. (Do the same as with admin/base_site.html in the previous section -- copy it from the default directory to your custom template directory.) Edit the file, and you'll see it uses a template variable called app_list. That variable contains every installed Django app. Instead of using that, you can hard-code links to object-specific admin pages in whatever way you think is best.
这篇关于订购admin.ModelAdmin对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!