问题描述
以同样的方式,您可以将 'classes': ['collapse'] 添加到您的 ModelAdmin 字段集之一,我希望能够让内联模型管理员可折叠.
In the same way you can add 'classes': ['collapse'] to one of your ModelAdmin fieldsets, I'd like to be able to have an Inline Model Admin be collapsible.
这张票,在管理界面中折叠内联相关对象,正是讨论了我想要的完成.但与此同时,在我们等待下一个版本时,最好的解决办法是什么?
This ticket, Collapse in admin interface for inline related objects, discusses exactly what I want to accomplish. But in the mean time, what's the best work around while we wait for the next release?
仅供参考:我想出了一个解决方案,但我认为存在更好的解决方案.我会让投票来处理它.
FYI: I've come up with a solution, but I think a better one exists. I'll let the voting take care of it.
推荐答案
您可以使用 grappelli - 它支持折叠字段集.它使用的解决方案与上面提到的解决方案非常相似,但 javascript/编码已经完成 - 您只需将 'classes':(collapse closed',) 添加到您的字段集(请参阅 http://readthedocs.org/docs/django-grappelli/en/latest/customization.html)
You can use grappelli - which supports collapsing fieldsets. It uses a solution much like the solutions mentioned above, but the javascript / coding is already done - you just have to add 'classes':(collapse closed',), to your fieldset ( see http://readthedocs.org/docs/django-grappelli/en/latest/customization.html)
例如:
class ModelOptions(admin.ModelAdmin):
fieldsets = (
('', {
'fields': ('title', 'subtitle', 'slug', 'pub_date', 'status',),
}),
('Flags', {
'classes': ('grp-collapse grp-closed',),
'fields' : ('flag_front', 'flag_sticky', 'flag_allow_comments', 'flag_comments_closed',),
}),
('Tags', {
'classes': ('grp-collapse grp-open',),
'fields' : ('tags',),
}),
)
class StackedItemInline(admin.StackedInline):
classes = ('grp-collapse grp-open',)
class TabularItemInline(admin.TabularInline):
classes = ('grp-collapse grp-open',)
这篇关于如何将“折叠"添加到 Django StackedInline的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!