开发者

Any way to add tabbed forms in django administration site?

开发者 https://www.devze.com 2022-12-25 21:37 出处:网络
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).

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

精彩评论

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