|
7 | 7 | from dcim.models import Device, Interface, Region, Site |
8 | 8 | from extras.filters import CustomFieldFilterSet, CreatedUpdatedFilterSet |
9 | 9 | from tenancy.filtersets import TenancyFilterSet |
10 | | -from utilities.filters import NameSlugSearchFilterSet, NumericInFilter, TagFilter, TreeNodeMultipleChoiceFilter |
| 10 | +from utilities.filters import NameSlugSearchFilterSet, NumericInFilter, TagFilter, TreeNodeMultipleChoiceFilter, MultiValueCharFilter |
11 | 11 | from virtualization.models import VirtualMachine |
12 | 12 | from .constants import * |
13 | 13 | from .models import Aggregate, IPAddress, Prefix, RIR, Role, Service, VLAN, VLANGroup, VRF |
@@ -271,7 +271,7 @@ class IPAddressFilter(TenancyFilterSet, CustomFieldFilterSet, CreatedUpdatedFilt |
271 | 271 | method='search_by_parent', |
272 | 272 | label='Parent prefix', |
273 | 273 | ) |
274 | | - address = django_filters.CharFilter( |
| 274 | + address = MultiValueCharFilter( |
275 | 275 | method='filter_address', |
276 | 276 | label='Address', |
277 | 277 | ) |
@@ -358,13 +358,11 @@ def search_by_parent(self, queryset, name, value): |
358 | 358 | return queryset.none() |
359 | 359 |
|
360 | 360 | def filter_address(self, queryset, name, value): |
361 | | - if not value.strip(): |
362 | | - return queryset |
363 | 361 | try: |
364 | | - # Match address and subnet mask |
365 | | - if '/' in value: |
366 | | - return queryset.filter(address=value) |
367 | | - return queryset.filter(address__net_host=value) |
| 362 | + return queryset.filter( |
| 363 | + Q(address__in=value) | |
| 364 | + Q(address__net_host_in=value) |
| 365 | + ) |
368 | 366 | except ValidationError: |
369 | 367 | return queryset.none() |
370 | 368 |
|
|
0 commit comments