订购 admin.ModelAdmin 对象 [英] Ordering admin.ModelAdmin objects

查看:11
本文介绍了订购 admin.ModelAdmin 对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我的披萨应用程序带有 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

但我希望它们是这样的:

But I want them like this:

PizzaApp
-
Pizzas        >>>>>>>>>>      Add / Change

Toppings      >>>>>>>>>>      Add / Change

如何在我的 admin.py 中配置它?

How do I configure that in my admin.py?

推荐答案

这实际上在 编写你的第一个 Django 应用,第 7 部分.

以下是相关部分:

自定义管理索引页面

在类似的说明中,您可能希望自定义外观和感觉Django 管理索引页面.

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.

要自定义的模板是管理员/index.html.(做同样的事情admin/base_site.html 在前面section - 从默认值复制它目录到您的自定义模板目录.)编辑文件,你会看到它使用了一个名为的模板变量应用程序列表.该变量包含每个安装了 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆