有什么方法可以在 django 管理站点中添加选项卡式表单吗?

发布于 2024-08-28 20:33:51 字数 217 浏览 4 评论 0原文

当使用 Django“开箱即用”管理表单时,对于复杂模型(具有很多字段),“更改表单”页面可能会相当长。

我想在“更改表单”中使用选项卡,这样事情就更具可读性(按选项卡对字段进行分组...)

而不是通过修改“change_form.html”管理模板来自己完成这一切,我想知道是否有人已经这样做并愿意分享代码,或者现有的 Django 插件是否已经存在。

预先感谢您的回答

When using Django "out-of-the-box" administration forms, the "change form" pages can be rather long for complex models (with a lot of fields).

I would like to use tabs in the "change form", so things can be more readable (group fields by tabs...)

Instead of doing it all by myself, by modifiying the 'change_form.html' admin template, I was wondering whether somebody has already done that and would like to share the code, or whether an existing Django-plugin already exist.

Thanks in advance for you answer

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

若无相欠,怎会相见 2024-09-04 20:33:51

我不确定这是否很容易开箱即用,但为什么不将字段放入字段集中并使这些字段集可折叠?它可能稍微不太理想,但开箱即用。 教程中有一个示例:

class PollAdmin(admin.ModelAdmin):
fieldsets = [
    (None,               {'fields': ['question']}),
    ('Date information', {'fields': ['pub_date'], 'classes': ['collapse']}),
]

在此示例中, “日期信息”字段集可以折叠到仅标题栏。

I'm not sure if this is easy to do out of the box, but why not put the fields in fieldsets and make these fieldsets collapsible? It's slightly less ideal possibly, but works out of the box. There's an example in the tutorial:

class PollAdmin(admin.ModelAdmin):
fieldsets = [
    (None,               {'fields': ['question']}),
    ('Date information', {'fields': ['pub_date'], 'classes': ['collapse']}),
]

In this example, the 'Date Information' fieldset can be collapsed to just the title bar.

所有深爱都是秘密 2024-09-04 20:33:51

我编写了一个小应用程序,可以非常轻松地做到这一点: https://github.com/omji/django- tabbed-admin

它尝试以与字段集相同的方式工作以保持 django 逻辑。您只需从选项卡式模型继承您的管理类。您还可以将其与内联混合并按照您想要的方式排序。例如:

class BandAdmin(TabbedModelAdmin):

    tab_overview = (
        (None, {
            'fields': ('name', 'bio', 'style')
        }),
        MusicianInline,
        ('Contact', {
            'fields': ('agent', 'phone', 'email')
        })
    )
    tab_album = (
        AlbumInline,
    )
    tabs = [
        ('Overview', tab_overview),
        ('Albums', tab_album)
    ]

I have written a small app do that very easily: https://github.com/omji/django-tabbed-admin

It attemps to work the same way as for the fieldsets to keep the django logic. You just inherit your admin class from the tabbed model. You can also mix it with inlines and order them the way you want. For exemple:

class BandAdmin(TabbedModelAdmin):

    tab_overview = (
        (None, {
            'fields': ('name', 'bio', 'style')
        }),
        MusicianInline,
        ('Contact', {
            'fields': ('agent', 'phone', 'email')
        })
    )
    tab_album = (
        AlbumInline,
    )
    tabs = [
        ('Overview', tab_overview),
        ('Albums', tab_album)
    ]
瘫痪情歌 2024-09-04 20:33:51

我知道执行此操作的三个选项:

  • 通过覆盖 admin/change_form.html 模板自行执行
  • 看一下 django-admin-tabs
  • 尝试 django-admintools-bootstrap (0.0 .2 分支)如果您有兴趣在 django-admin 中使用 twitter Bootstrap 主题(这太棒了!)

I know three options to do this :

  • Do it yourself by overriding the admin/change_form.html template
  • Have a look at django-admin-tabs
  • Try django-admintools-bootstrap (the 0.0.2 branch) if you're interested in using the twitter Bootstrap theme in django-admin (which is great!)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文