mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-01 13:26:25 -06:00
Include custom field filters in grouped filter form
This commit is contained in:
parent
27513aa062
commit
a4969af953
@ -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)
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -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 %}
|
||||||
|
Loading…
Reference in New Issue
Block a user