From 4b19073b8becd42d0d3a0622114b1ef9e46f9450 Mon Sep 17 00:00:00 2001 From: Saria Hajjar Date: Sat, 4 Jan 2020 13:30:31 +0000 Subject: [PATCH 1/2] Fixed #3187: Rack multi-selection field --- netbox/dcim/forms.py | 28 ++++++++++++++++++++++++++++ netbox/dcim/views.py | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/netbox/dcim/forms.py b/netbox/dcim/forms.py index a5ce2811c13..bbdbe251dc2 100644 --- a/netbox/dcim/forms.py +++ b/netbox/dcim/forms.py @@ -703,6 +703,34 @@ class RackFilterForm(BootstrapMixin, TenancyFilterForm, CustomFieldFilterForm): ) +# +# Rack elevations +# + +class RackElevationFilterForm(RackFilterForm): + field_order = ['q', 'region', 'site', 'group_id', 'id', 'status', 'role', 'tenant_group', 'tenant'] + id = ChainedModelChoiceField( + queryset=Rack.objects.all(), + label='Rack', + chains=( + ('site', 'site'), + ('group_id', 'group_id'), + ), + required=False, + widget=APISelectMultiple( + api_url='/api/dcim/racks/', + display_field='display_name', + ) + ) + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + # Filter the rack field based on the site and group + self.fields['site'].widget.add_filter_for('id', 'site') + self.fields['group_id'].widget.add_filter_for('id', 'group_id') + + # # Rack reservations # diff --git a/netbox/dcim/views.py b/netbox/dcim/views.py index 959e1043e6e..2d98515cfd1 100644 --- a/netbox/dcim/views.py +++ b/netbox/dcim/views.py @@ -388,7 +388,7 @@ def get(self, request): 'page': page, 'total_count': total_count, 'face_id': face_id, - 'filter_form': forms.RackFilterForm(request.GET), + 'filter_form': forms.RackElevationFilterForm(request.GET), }) From dba40cd6bc124629319da89b06bf7c3a839be7f5 Mon Sep 17 00:00:00 2001 From: Saria Hajjar Date: Sat, 4 Jan 2020 13:32:07 +0000 Subject: [PATCH 2/2] Changelog (may conflict because adding headers) --- docs/release-notes/version-2.6.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/release-notes/version-2.6.md b/docs/release-notes/version-2.6.md index 2bf55d85756..ccbcfb75464 100644 --- a/docs/release-notes/version-2.6.md +++ b/docs/release-notes/version-2.6.md @@ -1,3 +1,11 @@ +# v2.6.12 (FUTURE) + +## Enhancements + +* [#3187](https://github.com/netbox-community/netbox/issues/3187) - Add rack selection field to rack elevations + +--- + # v2.6.11 (2020-01-03) ## Bug Fixes