mirror of
https://github.com/netbox-community/netbox.git
synced 2026-01-16 16:52:17 -06:00
Support setting cable terminations from serialized CableTermination IDs
This commit is contained in:
@@ -146,12 +146,19 @@ class Cable(PrimaryModel):
|
|||||||
"""
|
"""
|
||||||
if side not in (CableEndChoices.SIDE_A, CableEndChoices.SIDE_B):
|
if side not in (CableEndChoices.SIDE_A, CableEndChoices.SIDE_B):
|
||||||
raise ValueError("Unknown cable side: {side")
|
raise ValueError("Unknown cable side: {side")
|
||||||
public_attr = f'{side.lower()}_terminations'
|
_attr = f'_{side.lower()}_terminations'
|
||||||
private_attr = f'_{public_attr}'
|
|
||||||
|
|
||||||
if not self.pk or getattr(self, public_attr) != list(value):
|
# If the provided value is a list of CableTermination IDs, resolve them
|
||||||
|
# to their corresponding termination objects.
|
||||||
|
if all(isinstance(item, int) for item in value):
|
||||||
|
value = [
|
||||||
|
ct.termination for ct in CableTermination.objects.filter(pk__in=value).prefetch_related('termination')
|
||||||
|
]
|
||||||
|
|
||||||
|
if not self.pk or getattr(self, _attr, []) != list(value):
|
||||||
self._terminations_modified = True
|
self._terminations_modified = True
|
||||||
setattr(self, private_attr, value)
|
|
||||||
|
setattr(self, _attr, value)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def a_terminations(self):
|
def a_terminations(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user