Add parent_prefixes to graphql IPAddressType

This commit is contained in:
Clint Armstrong 2025-04-09 09:23:26 -04:00
parent bf286df670
commit 006c22a54f
No known key found for this signature in database

View File

@ -138,6 +138,17 @@ class IPAddressType(NetBoxObjectType, ContactsMixin, BaseIPAddressFamilyType):
Annotated["VMInterfaceType", strawberry.lazy('virtualization.graphql.types')],
], strawberry.union("IPAddressAssignmentType")] | None:
return self.assigned_object
@strawberry_django.field
def parent_prefixes(self) -> List[Annotated["PrefixType", strawberry.lazy('ipam.graphql.types')]]:
"""
Return all prefixes containing this IP address.
"""
from ipam.models import Prefix
return Prefix.objects.filter(
vrf=self.vrf,
prefix__net_contains_or_equals=str(self.address.ip)
)
@strawberry_django.type(