From 5399ccc0f4257676981ef7937ea84be36f7058a6 Mon Sep 17 00:00:00 2001 From: Karen Tracey Date: Sat, 7 Nov 2015 10:46:50 -0500 Subject: [PATCH] Fixed #494 -- Added ability to specify classes on admin inline fieldsets. This includes the ability to collapse inlines by specifying a class named 'collapse'. --- django/contrib/admin/helpers.py | 1 + django/contrib/admin/options.py | 3 +++ .../templates/admin/edit_inline/stacked.html | 2 ++ .../templates/admin/edit_inline/tabular.html | 2 +- docs/ref/contrib/admin/index.txt | 10 ++++++++++ docs/releases/1.10.txt | 5 +++++ tests/admin_inlines/admin.py | 2 ++ tests/admin_inlines/tests.py | 19 +++++++++++++++++++ 8 files changed, 43 insertions(+), 1 deletion(-) 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 }}"> +

{{ inline_admin_formset.opts.verbose_name_plural|capfirst }}

{{ inline_admin_formset.formset.management_form }} {{ inline_admin_formset.formset.non_form_errors }} @@ -20,4 +21,5 @@ {% if inline_admin_form.needs_explicit_pk_field %}{{ inline_admin_form.pk_field.field }}{% endif %} {{ inline_admin_form.fk_field.field }} {% endfor %} +
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 }}">