1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00

#8054: Allow replacing default static choices

This commit is contained in:
jeremystretch
2022-02-03 13:52:42 -05:00
parent 6575af6b93
commit ac1c0b0715
2 changed files with 20 additions and 10 deletions

View File

@@ -8,12 +8,14 @@ class ChoiceSetMeta(type):
def __new__(mcs, name, bases, attrs):
# Extend static choices with any configured choices
key = attrs.get('key')
if key:
try:
attrs['CHOICES'].extend(settings.FIELD_CHOICES[key])
except KeyError:
pass
replace_key = attrs.get('key')
extend_key = f'{replace_key}+' if replace_key else None
if replace_key and replace_key in settings.FIELD_CHOICES:
# Replace the stock choices
attrs['CHOICES'] = settings.FIELD_CHOICES[replace_key]
elif extend_key and extend_key in settings.FIELD_CHOICES:
# Extend the stock choices
attrs['CHOICES'].extend(settings.FIELD_CHOICES[extend_key])
# Define choice tuples and color maps
attrs['_choices'] = []