mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-24 09:28:38 -06:00
Fixes #15609: Fix filtering providers list by assigned ASN
This commit is contained in:
parent
282dc7a705
commit
d9a7b4ee0e
@ -64,6 +64,12 @@ class ProviderFilterSet(NetBoxModelFilterSet, ContactModelFilterSet):
|
|||||||
queryset=ASN.objects.all(),
|
queryset=ASN.objects.all(),
|
||||||
label=_('ASN (ID)'),
|
label=_('ASN (ID)'),
|
||||||
)
|
)
|
||||||
|
asn = django_filters.ModelMultipleChoiceFilter(
|
||||||
|
field_name='asns__asn',
|
||||||
|
queryset=ASN.objects.all(),
|
||||||
|
to_field_name='asn',
|
||||||
|
label=_('ASN'),
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Provider
|
model = Provider
|
||||||
|
@ -24,7 +24,7 @@ class ProviderFilterForm(ContactModelFilterForm, NetBoxModelFilterSetForm):
|
|||||||
fieldsets = (
|
fieldsets = (
|
||||||
(None, ('q', 'filter_id', 'tag')),
|
(None, ('q', 'filter_id', 'tag')),
|
||||||
(_('Location'), ('region_id', 'site_group_id', 'site_id')),
|
(_('Location'), ('region_id', 'site_group_id', 'site_id')),
|
||||||
(_('ASN'), ('asn',)),
|
(_('ASN'), ('asn_id',)),
|
||||||
(_('Contacts'), ('contact', 'contact_role', 'contact_group')),
|
(_('Contacts'), ('contact', 'contact_role', 'contact_group')),
|
||||||
)
|
)
|
||||||
region_id = DynamicModelMultipleChoiceField(
|
region_id = DynamicModelMultipleChoiceField(
|
||||||
@ -46,10 +46,6 @@ class ProviderFilterForm(ContactModelFilterForm, NetBoxModelFilterSetForm):
|
|||||||
},
|
},
|
||||||
label=_('Site')
|
label=_('Site')
|
||||||
)
|
)
|
||||||
asn = forms.IntegerField(
|
|
||||||
required=False,
|
|
||||||
label=_('ASN (legacy)')
|
|
||||||
)
|
|
||||||
asn_id = DynamicModelMultipleChoiceField(
|
asn_id = DynamicModelMultipleChoiceField(
|
||||||
queryset=ASN.objects.all(),
|
queryset=ASN.objects.all(),
|
||||||
required=False,
|
required=False,
|
||||||
|
@ -90,10 +90,12 @@ class ProviderTestCase(TestCase, ChangeLoggedFilterSetTests):
|
|||||||
params = {'description': ['foobar1', 'foobar2']}
|
params = {'description': ['foobar1', 'foobar2']}
|
||||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||||
|
|
||||||
def test_asn_id(self): # ASN object assignment
|
def test_asn(self):
|
||||||
asns = ASN.objects.all()[:2]
|
asns = ASN.objects.all()[:2]
|
||||||
params = {'asn_id': [asns[0].pk, asns[1].pk]}
|
params = {'asn_id': [asns[0].pk, asns[1].pk]}
|
||||||
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
self.assertEqual(self.filterset(params, self.queryset).qs.count(), 2)
|
||||||
|
params = {'asn': [asns[0].asn, asns[1].asn]}
|
||||||
|
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]
|
||||||
|
Loading…
Reference in New Issue
Block a user