Skip to content

Commit 6f2c7e5

Browse files
author
Rinna Izumi
committed
Fixes #20422: Allow AggregateFilter and PrefixFilter to filter by family in GraphQL
1 parent e251ea1 commit 6f2c7e5

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

netbox/ipam/graphql/filters.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,14 @@ class AggregateFilter(ContactFilterMixin, TenancyFilterMixin, PrimaryModelFilter
8585
rir_id: ID | None = strawberry_django.filter_field()
8686
date_added: DateFilterLookup[date] | None = strawberry_django.filter_field()
8787

88+
@strawberry_django.filter_field()
89+
def family(
90+
self,
91+
value: Annotated['IPAddressFamilyEnum', strawberry.lazy('ipam.graphql.enums')],
92+
prefix,
93+
) -> Q:
94+
return Q(**{f"{prefix}prefix__family": value.value})
95+
8896

8997
@strawberry_django.filter_type(models.FHRPGroup, lookups=True)
9098
class FHRPGroupFilter(PrimaryModelFilterMixin):
@@ -261,6 +269,14 @@ def contains(self, value: list[str], prefix) -> Q:
261269
q |= Q(prefix__net_contains=query)
262270
return q
263271

272+
@strawberry_django.filter_field()
273+
def family(
274+
self,
275+
value: Annotated['IPAddressFamilyEnum', strawberry.lazy('ipam.graphql.enums')],
276+
prefix,
277+
) -> Q:
278+
return Q(**{f"{prefix}prefix__family": value.value})
279+
264280

265281
@strawberry_django.filter_type(models.RIR, lookups=True)
266282
class RIRFilter(OrganizationalModelFilterMixin):

0 commit comments

Comments
 (0)