mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-28 10:16:10 -06:00
Implement contains filter for IPAM IP ranges
This commit is contained in:
parent
0827198cad
commit
5d194214aa
@ -222,6 +222,19 @@ class IPRangeFilter(ContactFilterMixin, TenancyFilterMixin, PrimaryModelFilterMi
|
|||||||
return Q()
|
return Q()
|
||||||
return q
|
return q
|
||||||
|
|
||||||
|
@strawberry_django.filter_field()
|
||||||
|
def contains(self, value: list[str], prefix) -> Q:
|
||||||
|
if not value:
|
||||||
|
return Q()
|
||||||
|
q = Q()
|
||||||
|
for subnet in value:
|
||||||
|
net = netaddr.IPNetwork(subnet.strip())
|
||||||
|
q |= Q(
|
||||||
|
start_address__host__inet__lte=str(netaddr.IPAddress(net.first)),
|
||||||
|
end_address__host__inet__gte=str(netaddr.IPAddress(net.last)),
|
||||||
|
)
|
||||||
|
return q
|
||||||
|
|
||||||
|
|
||||||
@strawberry_django.filter_type(models.Prefix, lookups=True)
|
@strawberry_django.filter_type(models.Prefix, lookups=True)
|
||||||
class PrefixFilter(ContactFilterMixin, ScopedFilterMixin, TenancyFilterMixin, PrimaryModelFilterMixin):
|
class PrefixFilter(ContactFilterMixin, ScopedFilterMixin, TenancyFilterMixin, PrimaryModelFilterMixin):
|
||||||
|
Loading…
Reference in New Issue
Block a user