Fix link peers

This commit is contained in:
Andrey Tikhonov 2025-02-24 15:28:45 +01:00
parent 8dc1d68aee
commit 7794c6cfcb
2 changed files with 7 additions and 5 deletions

View File

@ -439,15 +439,14 @@ class InterfaceViewSet(PathEndpointMixin, NetBoxModelViewSet):
GenericPrefetch(
"cable__terminations__termination",
[
Interface.objects.prefetch_related("device"),
Interface.objects.select_related("device", "cable"),
],
),
Prefetch(
"_path",
CablePath.objects.prefetch_related(
GenericPrefetch("path_objects", [
Interface.objects.prefetch_related("device"),
Cable.objects.prefetch_related("terminations"),
Interface.objects.select_related("device"),
]),
)
),

View File

@ -189,8 +189,11 @@ class CabledObjectModel(models.Model):
@cached_property
def link_peers(self):
if self.cable:
peers = self.cable.terminations.exclude(cable_end=self.cable_end).prefetch_related('termination')
return [peer.termination for peer in peers]
return [
peer.termination
for peer in self.cable.terminations.all()
if peer.cable_end != self.cable_end
]
return []
@property