Andrey Tikhonov 1 год назад
Родитель
Сommit
7794c6cfcb
2 измененных файлов с 7 добавлено и 5 удалено
  1. 2 3
      netbox/dcim/api/views.py
  2. 5 2
      netbox/dcim/models/device_components.py

+ 2 - 3
netbox/dcim/api/views.py

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

+ 5 - 2
netbox/dcim/models/device_components.py

@@ -189,8 +189,11 @@ class CabledObjectModel(models.Model):
     @cached_property
     @cached_property
     def link_peers(self):
     def link_peers(self):
         if self.cable:
         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 []
         return []
 
 
     @property
     @property