mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-12 10:38:16 -06:00
14948 add has_virtual_device_cnotexts filter to device
This commit is contained in:
parent
6c51b89502
commit
581560fa8a
@ -1100,6 +1100,10 @@ class DeviceFilterSet(
|
|||||||
queryset=IPAddress.objects.all(),
|
queryset=IPAddress.objects.all(),
|
||||||
label=_('OOB IP (ID)'),
|
label=_('OOB IP (ID)'),
|
||||||
)
|
)
|
||||||
|
has_virtual_device_contexts = django_filters.BooleanFilter(
|
||||||
|
method='_has_virtual_device_contexts',
|
||||||
|
label=_('Has virtual device contexts'),
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Device
|
model = Device
|
||||||
@ -1176,6 +1180,12 @@ class DeviceFilterSet(
|
|||||||
def _device_bays(self, queryset, name, value):
|
def _device_bays(self, queryset, name, value):
|
||||||
return queryset.exclude(devicebays__isnull=value)
|
return queryset.exclude(devicebays__isnull=value)
|
||||||
|
|
||||||
|
def _has_virtual_device_contexts(self, queryset, name, value):
|
||||||
|
params = Q(vdcs__isnull=False)
|
||||||
|
if value:
|
||||||
|
return queryset.filter(params).distinct()
|
||||||
|
return queryset.exclude(params)
|
||||||
|
|
||||||
|
|
||||||
class VirtualDeviceContextFilterSet(NetBoxModelFilterSet, TenancyFilterSet, PrimaryIPFilterSet):
|
class VirtualDeviceContextFilterSet(NetBoxModelFilterSet, TenancyFilterSet, PrimaryIPFilterSet):
|
||||||
device_id = django_filters.ModelMultipleChoiceFilter(
|
device_id = django_filters.ModelMultipleChoiceFilter(
|
||||||
|
@ -657,6 +657,7 @@ class DeviceFilterForm(
|
|||||||
),
|
),
|
||||||
FieldSet(
|
FieldSet(
|
||||||
'has_primary_ip', 'has_oob_ip', 'virtual_chassis_member', 'config_template_id', 'local_context_data',
|
'has_primary_ip', 'has_oob_ip', 'virtual_chassis_member', 'config_template_id', 'local_context_data',
|
||||||
|
'has_virtual_device_contexts',
|
||||||
name=_('Miscellaneous')
|
name=_('Miscellaneous')
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -813,6 +814,13 @@ class DeviceFilterForm(
|
|||||||
choices=BOOLEAN_WITH_BLANK_CHOICES
|
choices=BOOLEAN_WITH_BLANK_CHOICES
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
has_virtual_device_contexts = forms.NullBooleanField(
|
||||||
|
required=False,
|
||||||
|
label=_('Has virtual device contexts'),
|
||||||
|
widget=forms.Select(
|
||||||
|
choices=BOOLEAN_WITH_BLANK_CHOICES
|
||||||
|
)
|
||||||
|
)
|
||||||
tag = TagFilterField(model)
|
tag = TagFilterField(model)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user