mirror of
https://github.com/django/django.git
synced 2025-10-29 00:26:07 +00:00
Fixed #494 -- Added ability to specify classes on admin inline fieldsets.
This includes the ability to collapse inlines by specifying a class named 'collapse'.
This commit is contained in:
@@ -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()):
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
id="{{ inline_admin_formset.formset.prefix }}-group"
|
||||
data-inline-type="stacked"
|
||||
data-inline-formset="{{ inline_admin_formset.inline_formset_data }}">
|
||||
<fieldset class="module {{ inline_admin_formset.classes }}">
|
||||
<h2>{{ inline_admin_formset.opts.verbose_name_plural|capfirst }}</h2>
|
||||
{{ 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 }}
|
||||
</div>{% endfor %}
|
||||
</fieldset>
|
||||
</div>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
data-inline-formset="{{ inline_admin_formset.inline_formset_data }}">
|
||||
<div class="tabular inline-related {% if forloop.last %}last-related{% endif %}">
|
||||
{{ inline_admin_formset.formset.management_form }}
|
||||
<fieldset class="module">
|
||||
<fieldset class="module {{ inline_admin_formset.classes }}">
|
||||
<h2>{{ inline_admin_formset.opts.verbose_name_plural|capfirst }}</h2>
|
||||
{{ inline_admin_formset.formset.non_form_errors }}
|
||||
<table>
|
||||
|
||||
Reference in New Issue
Block a user