diff --git a/django/contrib/admin/helpers.py b/django/contrib/admin/helpers.py index 1217bd78df..9cb49473fd 100644 --- a/django/contrib/admin/helpers.py +++ b/django/contrib/admin/helpers.py @@ -235,6 +235,7 @@ class InlineAdminFormSet(object): if prepopulated_fields is None: prepopulated_fields = {} self.prepopulated_fields = prepopulated_fields + self.classes = ' '.join(inline.classes) if inline.classes else '' def __iter__(self): for form, original in zip(self.formset.initial_forms, self.formset.get_queryset()): diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index 4fb5f3ddc8..42880aba81 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -1800,6 +1800,7 @@ class InlineModelAdmin(BaseModelAdmin): can_delete = True show_change_link = False checks_class = InlineModelAdminChecks + classes = None def __init__(self, parent_model, admin_site): self.admin_site = admin_site @@ -1819,6 +1820,8 @@ class InlineModelAdmin(BaseModelAdmin): 'inlines%s.js' % extra] if self.filter_vertical or self.filter_horizontal: js.extend(['SelectBox.js', 'SelectFilter2.js']) + if self.classes and 'collapse' in self.classes: + js.append('collapse%s.js' % extra) return forms.Media(js=['admin/js/%s' % url for url in js]) def get_extra(self, request, obj=None, **kwargs): diff --git a/django/contrib/admin/templates/admin/edit_inline/stacked.html b/django/contrib/admin/templates/admin/edit_inline/stacked.html index 9025a17afb..65af259a21 100644 --- a/django/contrib/admin/templates/admin/edit_inline/stacked.html +++ b/django/contrib/admin/templates/admin/edit_inline/stacked.html @@ -3,6 +3,7 @@ id="{{ inline_admin_formset.formset.prefix }}-group" data-inline-type="stacked" data-inline-formset="{{ inline_admin_formset.inline_formset_data }}"> +
diff --git a/django/contrib/admin/templates/admin/edit_inline/tabular.html b/django/contrib/admin/templates/admin/edit_inline/tabular.html index bcf3e6bd1c..f04faadf2f 100644 --- a/django/contrib/admin/templates/admin/edit_inline/tabular.html +++ b/django/contrib/admin/templates/admin/edit_inline/tabular.html @@ -4,7 +4,7 @@ data-inline-formset="{{ inline_admin_formset.inline_formset_data }}">