开发者

Any way to add tabbed forms in django administration site?

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


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.


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)
    ]


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!)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜