【问题标题】:Display a many-to-many relation in admin without need to edit children在管理员中显示多对多关系,无需编辑子项
【发布时间】:2016-01-26 17:45:30
【问题描述】:

我的模型是:

class CustomerAccount(models.Model):
    name = models.CharField(max_length=50)


class MyUser(AbstractUser):
    customer_account = models.ManyToManyField(CustomerAccount, related_name='users', blank=True)
    default_customer_account = models.ForeignKey(CustomerAccount, related_name='users_using_default_account', null=True, blank=True)

我想在 CustomerAccount 的管理界面中显示这样的东西:

我不需要在 CustomerAccount 界面中添加 MyUser。

大多数 SO 问题和文档都与在管理员中显示内联类有关,但我不需要它。

我该怎么办?

【问题讨论】:

    标签: django django-admin many-to-many


    【解决方案1】:

    您可以通过将所需字段添加到 filter_horizo​​ntal 列表 (docu) 来获得上面显示的功能。

    【讨论】:

    • 不,文档是相反的:filter_horizo​​ntal 将在 MyUser 管理员中,我希望它给 CustomerAccount 管理员。而且我无法更改模型。
    • 你想反过来添加它吗?你的意思是你根本不能改变模型——你能专门处理多对多字段吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-10-23
    • 2011-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多