Include custom field filters in grouped filter form

This commit is contained in:
jeremystretch 2021-08-06 14:30:46 -04:00
parent 27513aa062
commit a4969af953
2 changed files with 12 additions and 25 deletions

View File

@ -519,12 +519,14 @@ class CustomFieldModelFilterForm(forms.Form):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
# Add all applicable CustomFields to the form # Add all applicable CustomFields to the form
self.custom_field_filters = []
custom_fields = CustomField.objects.filter(content_types=self.obj_type).exclude( custom_fields = CustomField.objects.filter(content_types=self.obj_type).exclude(
filter_logic=CustomFieldFilterLogicChoices.FILTER_DISABLED filter_logic=CustomFieldFilterLogicChoices.FILTER_DISABLED
) )
for cf in custom_fields: for cf in custom_fields:
field_name = 'cf_{}'.format(cf.name) field_name = 'cf_{}'.format(cf.name)
self.fields[field_name] = cf.to_form_field(set_initial=True, enforce_required=False) self.fields[field_name] = cf.to_form_field(set_initial=True, enforce_required=False)
self.custom_field_filters.append(field_name)
# #

View File

@ -12,38 +12,23 @@
<div class="col col-12"> <div class="col col-12">
{% for name in group %} {% for name in group %}
{% with field=filter_form|get_item:name %} {% with field=filter_form|get_item:name %}
{% if field|widget_type == 'checkboxinput' %} {% render_field field %}
<div class="form-check mb-3">
<label class="form-check-label" for="{{ field.id_for_label }}">{{ field.label }}</label>
{{ field }}
</div>
{% else %}
<div class="mb-3 px-2">
<label class="form-label" for="{{ field.id_for_label }}">{{ field.label }}</label>
{{ field }}
</div>
{% endif %}
{% endwith %} {% endwith %}
{% endfor %} {% endfor %}
</div> </div>
{% if forloop.counter != filter_form.field_groups|length %} <hr class="card-divider mt-0" />
<hr class="card-divider mt-0" /> {% endfor %}
{% endif %} {% for name in filter_form.custom_field_filters %}
<div class="col col-12">
{% with field=filter_form|get_item:name %}
{% render_field field %}
{% endwith %}
</div>
{% endfor %} {% endfor %}
{% else %} {% else %}
{% for field in filter_form.visible_fields %} {% for field in filter_form.visible_fields %}
<div class="col col-12"> <div class="col col-12">
{% if field|widget_type == 'checkboxinput' %} {% render_field field %}
<div class="form-check mb-3">
<label class="form-check-label" for="{{ field.id_for_label }}">{{ field.label }}</label>
{{ field }}
</div>
{% else %}
<div class="mb-3 px-2">
<label class="form-label" for="{{ field.id_for_label }}">{{ field.label }}</label>
{{ field }}
</div>
{% endif %}
</div> </div>
{% endfor %} {% endfor %}
{% endif %} {% endif %}