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.
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)
for example:
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',)
I came up with this solution using jQuery that works on TabularInline
var selector = "h2:contains('TITLE_OF_INLINE_BLOCK')";
$(selector).parent().addClass("collapsed");
$(selector).append(" (<a class=\"collapse-toggle\" id=\"customcollapser\" href=\"#\"> Show </a>)");
$("#customcollapser").click(function() {
$(selector).parent().toggleClass("collapsed");
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With