소스 검색

Return no terminations if the cable is unsaved

kkthxbye-code 3 년 전
부모
커밋
f7b85ab941
1개의 변경된 파일8개의 추가작업 그리고 0개의 파일을 삭제
  1. 8 0
      netbox/dcim/models/cables.py

+ 8 - 0
netbox/dcim/models/cables.py

@@ -112,6 +112,10 @@ class Cable(PrimaryModel):
     def a_terminations(self):
         if hasattr(self, '_a_terminations'):
             return self._a_terminations
+
+        if not self.pk:
+            return []
+
         # Query self.terminations.all() to leverage cached results
         return [
             ct.termination for ct in self.terminations.all() if ct.cable_end == CableEndChoices.SIDE_A
@@ -127,6 +131,10 @@ class Cable(PrimaryModel):
     def b_terminations(self):
         if hasattr(self, '_b_terminations'):
             return self._b_terminations
+
+        if not self.pk:
+            return []
+
         # Query self.terminations.all() to leverage cached results
         return [
             ct.termination for ct in self.terminations.all() if ct.cable_end == CableEndChoices.SIDE_B