mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-25 18:08:38 -06:00
Check that ChoiceSet CHOICES is mutable if key is set
This commit is contained in:
parent
fcfdbfc2b5
commit
830b56ac9e
@ -9,6 +9,7 @@ class ChoiceSetMeta(type):
|
|||||||
|
|
||||||
# Extend static choices with any configured choices
|
# Extend static choices with any configured choices
|
||||||
if key := attrs.get('key'):
|
if key := attrs.get('key'):
|
||||||
|
assert type(attrs['CHOICES']) is list, f"{name} has a key defined but CHOICES is not a list"
|
||||||
app = attrs['__module__'].split('.', 1)[0]
|
app = attrs['__module__'].split('.', 1)[0]
|
||||||
replace_key = f'{app}.{key}'
|
replace_key = f'{app}.{key}'
|
||||||
extend_key = f'{replace_key}+' if replace_key else None
|
extend_key = f'{replace_key}+' if replace_key else None
|
||||||
@ -47,7 +48,7 @@ class ChoiceSetMeta(type):
|
|||||||
|
|
||||||
class ChoiceSet(metaclass=ChoiceSetMeta):
|
class ChoiceSet(metaclass=ChoiceSetMeta):
|
||||||
"""
|
"""
|
||||||
Holds an interable of choice tuples suitable for passing to a Django model or form field. Choices can be defined
|
Holds an iterable of choice tuples suitable for passing to a Django model or form field. Choices can be defined
|
||||||
statically within the class as CHOICES and/or gleaned from the FIELD_CHOICES configuration parameter.
|
statically within the class as CHOICES and/or gleaned from the FIELD_CHOICES configuration parameter.
|
||||||
"""
|
"""
|
||||||
CHOICES = list()
|
CHOICES = list()
|
||||||
|
Loading…
Reference in New Issue
Block a user