diff --git a/netbox/extras/forms.py b/netbox/extras/forms.py index 98f34dfa9..18398a4fd 100644 --- a/netbox/extras/forms.py +++ b/netbox/extras/forms.py @@ -519,12 +519,14 @@ class CustomFieldModelFilterForm(forms.Form): super().__init__(*args, **kwargs) # Add all applicable CustomFields to the form + self.custom_field_filters = [] custom_fields = CustomField.objects.filter(content_types=self.obj_type).exclude( filter_logic=CustomFieldFilterLogicChoices.FILTER_DISABLED ) for cf in custom_fields: field_name = 'cf_{}'.format(cf.name) self.fields[field_name] = cf.to_form_field(set_initial=True, enforce_required=False) + self.custom_field_filters.append(field_name) # diff --git a/netbox/templates/inc/filter_list.html b/netbox/templates/inc/filter_list.html index 0e65acff5..4da03b5cc 100644 --- a/netbox/templates/inc/filter_list.html +++ b/netbox/templates/inc/filter_list.html @@ -12,38 +12,23 @@
{% for name in group %} {% with field=filter_form|get_item:name %} - {% if field|widget_type == 'checkboxinput' %} -
- - {{ field }} -
- {% else %} -
- - {{ field }} -
- {% endif %} + {% render_field field %} {% endwith %} {% endfor %}
- {% if forloop.counter != filter_form.field_groups|length %} -
- {% endif %} +
+ {% endfor %} + {% for name in filter_form.custom_field_filters %} +
+ {% with field=filter_form|get_item:name %} + {% render_field field %} + {% endwith %} +
{% endfor %} {% else %} {% for field in filter_form.visible_fields %}
- {% if field|widget_type == 'checkboxinput' %} -
- - {{ field }} -
- {% else %} -
- - {{ field }} -
- {% endif %} + {% render_field field %}
{% endfor %} {% endif %}