如何在Django管理员索引中的不同模块中分离模型? [英] How to separate models in different modules in Django admin's index?

查看:63
本文介绍了如何在Django管理员索引中的不同模块中分离模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在admin索引中分隔应用程序的模型:

I would like to separate my app's models in the admin index:

我将所有模型都注册在 admin.py ,然后将它们全部显示在默认管理索引下的红色大红色下,如下所示。

I registered all my models in admin.py and I get all of them in the default admin index under the big red 1 shown below.

现在我想将我的一些模型放在另一个模型中块,如下所示,在大红色2下方。

Now I'd like to have some of my models in another "block", as shown below under the big red 2.

为了更难一点,我还需要在两个块中都有一些模型,但是要使用不同的查询集

To make it harder, I also need to have some models in both "blocks", but with different queryset.

我该怎么办?

推荐答案

我测试了我的解决方案,它可以工作。

I tested my solution and it works.

执行以下操作:

class MyModelTest(models.Model):
    # Fields here
    class Meta:
        app_label = 'My other app namespace'






更新:


UPDATE:

要实现目标(最大灵活性),您需要修改模板 admin / app_index.html 和视图 django.contrib.admin.sites.app_index 来满足您的需求。

To achieve your goal (max flexibility) , you will need to modify the template admin/app_index.html and the view django.contrib.admin.sites.app_index to your own needs.

这篇关于如何在Django管理员索引中的不同模块中分离模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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