mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-22 20:12:00 -06:00
Merge pull request #5596 from FragmentedPacket/5586-vc-filtering
Closes 5586: Adds name, master, and master_id filtering
This commit is contained in:
commit
58699a220b
@ -1016,6 +1016,16 @@ class VirtualChassisFilterSet(BaseFilterSet):
|
|||||||
method='search',
|
method='search',
|
||||||
label='Search',
|
label='Search',
|
||||||
)
|
)
|
||||||
|
master_id = django_filters.ModelMultipleChoiceFilter(
|
||||||
|
queryset=Device.objects.all(),
|
||||||
|
label='Master (ID)',
|
||||||
|
)
|
||||||
|
master = django_filters.ModelMultipleChoiceFilter(
|
||||||
|
field_name='master__name',
|
||||||
|
queryset=Device.objects.all(),
|
||||||
|
to_field_name='name',
|
||||||
|
label='Master (name)',
|
||||||
|
)
|
||||||
region_id = TreeNodeMultipleChoiceFilter(
|
region_id = TreeNodeMultipleChoiceFilter(
|
||||||
queryset=Region.objects.all(),
|
queryset=Region.objects.all(),
|
||||||
field_name='master__site__region',
|
field_name='master__site__region',
|
||||||
@ -1055,7 +1065,7 @@ class VirtualChassisFilterSet(BaseFilterSet):
|
|||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = VirtualChassis
|
model = VirtualChassis
|
||||||
fields = ['id', 'domain']
|
fields = ['id', 'domain', 'name']
|
||||||
|
|
||||||
def search(self, queryset, name, value):
|
def search(self, queryset, name, value):
|
||||||
if not value.strip():
|
if not value.strip():
|
||||||
|
@ -2399,9 +2399,9 @@ class VirtualChassisTestCase(TestCase):
|
|||||||
Device.objects.bulk_create(devices)
|
Device.objects.bulk_create(devices)
|
||||||
|
|
||||||
virtual_chassis = (
|
virtual_chassis = (
|
||||||
VirtualChassis(master=devices[0], domain='Domain 1'),
|
VirtualChassis(name='VC 1', master=devices[0], domain='Domain 1'),
|
||||||
VirtualChassis(master=devices[2], domain='Domain 2'),
|
VirtualChassis(name='VC 2', master=devices[2], domain='Domain 2'),
|
||||||
VirtualChassis(master=devices[4], domain='Domain 3'),
|
VirtualChassis(name='VC 3', master=devices[4], domain='Domain 3'),
|
||||||
)
|
)
|
||||||
VirtualChassis.objects.bulk_create(virtual_chassis)
|
VirtualChassis.objects.bulk_create(virtual_chassis)
|
||||||
|
|
||||||
@ -2417,6 +2417,17 @@ class VirtualChassisTestCase(TestCase):
|
|||||||
params = {'domain': ['Domain 1', 'Domain 2']}
|
params = {'domain': ['Domain 1', 'Domain 2']}
|
||||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||||
|
|
||||||
|
def test_master(self):
|
||||||
|
masters = Device.objects.all()
|
||||||
|
params = {'master_id': [masters[0].pk, masters[2].pk]}
|
||||||
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||||
|
params = {'master': [masters[0].name, masters[2].name]}
|
||||||
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||||
|
|
||||||
|
def test_name(self):
|
||||||
|
params = {'name': ['VC 1', 'VC 2']}
|
||||||
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||||
|
|
||||||
def test_region(self):
|
def test_region(self):
|
||||||
regions = Region.objects.all()[:2]
|
regions = Region.objects.all()[:2]
|
||||||
params = {'region_id': [regions[0].pk, regions[1].pk]}
|
params = {'region_id': [regions[0].pk, regions[1].pk]}
|
||||||
|
Loading…
Reference in New Issue
Block a user