Remove debug and do some cleanup
Some checks failed
CI / build (20.x, 3.10) (push) Has been cancelled
CI / build (20.x, 3.11) (push) Has been cancelled
CI / build (20.x, 3.12) (push) Has been cancelled

This commit is contained in:
Daniel Sheppard 2025-08-07 21:24:08 -05:00
parent a3322d9cc2
commit 6a42d7c69d

View File

@ -811,31 +811,28 @@ class ServiceForm(NetBoxModelForm):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
if (parent_object_type_id := get_field_value(self, 'parent_object_type')): if parent_object_type_id := get_field_value(self, 'parent_object_type'):
try: try:
parent_type = ContentType.objects.get(pk=parent_object_type_id) parent_type = ContentType.objects.get(pk=parent_object_type_id)
if parent_type.model_class() == Device: model = parent_type.model_class()
if model == Device:
self.fields['ipaddresses'].widget.add_query_params({ self.fields['ipaddresses'].widget.add_query_params({
'device_id': '$parent', 'device_id': '$parent',
}) })
elif parent_type.model_class() == VirtualMachine: elif model == VirtualMachine:
self.fields['ipaddresses'].widget.add_query_params({ self.fields['ipaddresses'].widget.add_query_params({
'virtual_machine_id': '$parent', 'virtual_machine_id': '$parent',
}) })
elif parent_type.model_class() == FHRPGroup: elif model == FHRPGroup:
self.fields['ipaddresses'].widget.add_query_params({ self.fields['ipaddresses'].widget.add_query_params({
'fhrpgroup_id': '$parent', 'fhrpgroup_id': '$parent',
}) })
model = parent_type.model_class()
self.fields['parent'].queryset = model.objects.all() self.fields['parent'].queryset = model.objects.all()
self.fields['parent'].widget.attrs['selector'] = model._meta.label_lower self.fields['parent'].widget.attrs['selector'] = model._meta.label_lower
self.fields['parent'].disabled = False self.fields['parent'].disabled = False
self.fields['parent'].label = _(bettertitle(model._meta.verbose_name)) self.fields['parent'].label = _(bettertitle(model._meta.verbose_name))
except ObjectDoesNotExist: except ObjectDoesNotExist:
print('Except')
pass pass
else:
print('No obj_type')
if self.instance and self.instance.pk and parent_object_type_id != self.instance.parent_object_type_id: if self.instance and self.instance.pk and parent_object_type_id != self.instance.parent_object_type_id:
self.initial['parent'] = None self.initial['parent'] = None