15973 fix cable add from device
This commit is contained in:
parent
949c9f3d5e
commit
07288e4b61
|
@ -91,14 +91,13 @@ def get_cable_form(a_type, b_type):
|
|||
|
||||
def __init__(self, *args, initial=None, **kwargs):
|
||||
initial = initial or {}
|
||||
|
||||
if a_type:
|
||||
a_ct = ContentType.objects.get_for_model(a_type)
|
||||
initial['a_terminations_type'] = f'{a_ct.app_label}.{a_ct.model}'
|
||||
initial.pop('a_terminations', None)
|
||||
if b_type:
|
||||
b_ct = ContentType.objects.get_for_model(b_type)
|
||||
initial['b_terminations_type'] = f'{b_ct.app_label}.{b_ct.model}'
|
||||
initial.pop('b_terminations', None)
|
||||
|
||||
# TODO: Temporary hack to work around list handling limitations with utils.normalize_querydict()
|
||||
for field_name in ('a_terminations', 'b_terminations'):
|
||||
|
@ -113,6 +112,13 @@ def get_cable_form(a_type, b_type):
|
|||
self.initial['a_terminations'] = self.instance.a_terminations
|
||||
if b_type and self.instance.b_terminations and b_ct == ContentType.objects.get_for_model(self.instance.b_terminations[0]):
|
||||
self.initial['b_terminations'] = self.instance.b_terminations
|
||||
else:
|
||||
# Need to clear terminations if swapped type - but need to do it only
|
||||
# if not from instance
|
||||
if a_type:
|
||||
initial.pop('a_terminations', None)
|
||||
if b_type:
|
||||
initial.pop('b_terminations', None)
|
||||
|
||||
def clean(self):
|
||||
super().clean()
|
||||
|
|
Loading…
Reference in New Issue