mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-27 02:48:38 -06:00
ordering for child and parent prefixes
This commit is contained in:
parent
362273deda
commit
d6e7e59c96
@ -142,13 +142,14 @@ class IPAddressType(NetBoxObjectType, ContactsMixin, BaseIPAddressFamilyType):
|
|||||||
@strawberry_django.field
|
@strawberry_django.field
|
||||||
def parent_prefixes(self) -> List[Annotated["PrefixType", strawberry.lazy('ipam.graphql.types')]]:
|
def parent_prefixes(self) -> List[Annotated["PrefixType", strawberry.lazy('ipam.graphql.types')]]:
|
||||||
"""
|
"""
|
||||||
Return all prefixes containing this IP address.
|
Return all prefixes containing this IP address, sorted by depth in descending order.
|
||||||
|
The closest containing parent prefix will be first.
|
||||||
"""
|
"""
|
||||||
from ipam.models import Prefix
|
from ipam.models import Prefix
|
||||||
return Prefix.objects.filter(
|
return Prefix.objects.filter(
|
||||||
vrf=self.vrf,
|
vrf=self.vrf,
|
||||||
prefix__net_contains_or_equals=str(self.address.ip)
|
prefix__net_contains_or_equals=str(self.address.ip)
|
||||||
)
|
).order_by('-_depth')
|
||||||
|
|
||||||
|
|
||||||
@strawberry_django.type(
|
@strawberry_django.type(
|
||||||
@ -188,24 +189,27 @@ class PrefixType(NetBoxObjectType, ContactsMixin, BaseIPAddressFamilyType):
|
|||||||
@strawberry_django.field
|
@strawberry_django.field
|
||||||
def parent_prefixes(self) -> List[Annotated["PrefixType", strawberry.lazy('ipam.graphql.types')]]:
|
def parent_prefixes(self) -> List[Annotated["PrefixType", strawberry.lazy('ipam.graphql.types')]]:
|
||||||
"""
|
"""
|
||||||
Return all parent prefixes containing this prefix.
|
Return all parent prefixes containing this prefix, sorted by depth in descending order.
|
||||||
|
The closest containing parent prefix will be first.
|
||||||
"""
|
"""
|
||||||
from ipam.models import Prefix
|
from ipam.models import Prefix
|
||||||
return Prefix.objects.filter(
|
return Prefix.objects.filter(
|
||||||
vrf=self.vrf,
|
vrf=self.vrf,
|
||||||
prefix__net_contains=str(self.prefix)
|
prefix__net_contains=str(self.prefix)
|
||||||
)
|
).order_by('-_depth')
|
||||||
|
|
||||||
@strawberry_django.field
|
@strawberry_django.field
|
||||||
def child_prefixes(self) -> List[Annotated["PrefixType", strawberry.lazy('ipam.graphql.types')]]:
|
def child_prefixes(self) -> List[Annotated["PrefixType", strawberry.lazy('ipam.graphql.types')]]:
|
||||||
"""
|
"""
|
||||||
Return all child prefixes contained within this prefix.
|
Return all child prefixes contained within this prefix, sorted by depth and then by network.
|
||||||
"""
|
"""
|
||||||
from ipam.models import Prefix
|
from ipam.models import Prefix
|
||||||
|
|
||||||
|
# Get child prefixes sorted by depth first and then by prefix naturally
|
||||||
return Prefix.objects.filter(
|
return Prefix.objects.filter(
|
||||||
vrf=self.vrf,
|
vrf=self.vrf,
|
||||||
prefix__net_contained=str(self.prefix)
|
prefix__net_contained=str(self.prefix)
|
||||||
)
|
).order_by('_depth', 'prefix')
|
||||||
|
|
||||||
@strawberry_django.field
|
@strawberry_django.field
|
||||||
def child_ip_addresses(self) -> List[Annotated["IPAddressType", strawberry.lazy('ipam.graphql.types')]]:
|
def child_ip_addresses(self) -> List[Annotated["IPAddressType", strawberry.lazy('ipam.graphql.types')]]:
|
||||||
|
Loading…
Reference in New Issue
Block a user