mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-28 03:16:25 -06:00
Change __init__ of CustomFieldChoiceSetForm to setup extra_choices
This commit is contained in:
parent
8114492673
commit
e15638f7be
@ -178,12 +178,15 @@ class CustomFieldChoiceSetForm(forms.ModelForm):
|
|||||||
def __init__(self, *args, initial=None, **kwargs):
|
def __init__(self, *args, initial=None, **kwargs):
|
||||||
super().__init__(*args, initial=initial, **kwargs)
|
super().__init__(*args, initial=initial, **kwargs)
|
||||||
|
|
||||||
# Escape colons in extra_choices
|
# Convert extra_choices Array Field from model to CharField for form
|
||||||
if 'extra_choices' in self.initial and self.initial['extra_choices']:
|
if 'extra_choices' in self.initial and self.initial['extra_choices']:
|
||||||
choices = []
|
extra_choices = self.initial['extra_choices']
|
||||||
for choice in self.initial['extra_choices']:
|
if isinstance(extra_choices, str):
|
||||||
choice = (choice[0].replace(':', '\\:'), choice[1].replace(':', '\\:'))
|
extra_choices = [extra_choices]
|
||||||
choices.append(choice)
|
choices = ""
|
||||||
|
for choice in extra_choices:
|
||||||
|
choice_str = ":".join(choice.replace("'", "").replace(" ", "")[1:-1].split(","))
|
||||||
|
choices += choice_str + "\n"
|
||||||
|
|
||||||
self.initial['extra_choices'] = choices
|
self.initial['extra_choices'] = choices
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user