mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-23 07:56:44 -06:00
14033 move check to cable model clean
This commit is contained in:
parent
77d205d65f
commit
002cb3c896
@ -103,10 +103,4 @@ def get_cable_form(a_type, b_type):
|
||||
self.instance.a_terminations = self.cleaned_data['a_terminations']
|
||||
self.instance.b_terminations = self.cleaned_data['b_terminations']
|
||||
|
||||
if a_type == b_type and self.instance.a_terminations and self.instance.b_terminations:
|
||||
if self.instance.a_terminations.intersection(self.instance.b_terminations):
|
||||
raise forms.ValidationError(
|
||||
_("A and B terminations cannot connect to the same object.")
|
||||
)
|
||||
|
||||
return _CableForm
|
||||
|
@ -180,6 +180,12 @@ class Cable(PrimaryModel):
|
||||
if b_type not in COMPATIBLE_TERMINATION_TYPES.get(a_type):
|
||||
raise ValidationError(f"Incompatible termination types: {a_type} and {b_type}")
|
||||
|
||||
if a_type == b_type:
|
||||
if (set(self.a_terminations) & set(self.b_terminations)):
|
||||
raise ValidationError(
|
||||
_("A and B terminations cannot connect to the same object.")
|
||||
)
|
||||
|
||||
# Run clean() on any new CableTerminations
|
||||
for termination in self.a_terminations:
|
||||
CableTermination(cable=self, cable_end='A', termination=termination).clean()
|
||||
|
Loading…
Reference in New Issue
Block a user