8

如何让 Django 管理员水平显示组?如果我有 3 个相邻的日期时间字段,我宁愿它们占据 1 行,而不是 3 行。

4

3 回答 3

16

您是否尝试过将您的字段集分组为元组?:

fieldsets = (
        (None, {
            'fields': ('name','description',('start_date','end_date'), 'location', ('latitude','longitude'))
        }),
    )
于 2009-04-22T09:28:39.630 回答
1

我这样做的方式是制作一个自定义管理模板。你可以拿 django 自带的那个,复制它,然后编辑你想要改变的部分。

关于如何做到这一点的一个很好的教程在 django 网站上。具体来说,有一个关于 制作自定义管理模板的部分。

于 2009-04-21T19:56:29.397 回答
1

它已经在 Django==2.0.7 上进行了测试并且工作起来就像一个魅力,关于使用参数“fieldsets”的一个非常重要的建议是你不能同时使用“fields”属性,否则你会得到您的控制台上出现以下错误:

(admin.E005) Both 'fieldsets' and 'fields' are specified.

语法会像这样:

fieldsets = (
    ('General Information', {
        'fields': (
            ("id", "created_at", "updated_at",),
            ("name", "coupon_type", "discount", "is_active",),
            ("quantity", "minumum_quantity", "before_expire",),
        ),
    }),
    ('Expiration Dates', {
        'fields': (
            ("expiration_from", "expiration_to",),
        ),
    }),
    ('Grants for', {
        'fields': (
            "products", "campaigns_product", "sellers", "platforms",
        ),
    }),
)
于 2020-02-20T21:57:41.063 回答