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

ChoiceSet cleanup

This commit is contained in:
jeremystretch
2021-12-16 10:31:32 -05:00
parent 1902ecb8ca
commit d8be8e25a5

View File

@ -34,16 +34,18 @@ class ChoiceSetMeta(type):
return super().__new__(mcs, name, bases, attrs)
def __call__(cls, *args, **kwargs):
# Django will check if a 'choices' value is callable, and if so assume that it returns an iterable
# django-filters will check if a 'choices' value is callable, and if so assume that it returns an iterable
return getattr(cls, '_choices', ())
def __iter__(cls):
choices = getattr(cls, '_choices', ())
return iter(choices)
return iter(getattr(cls, '_choices', ()))
class ChoiceSet(metaclass=ChoiceSetMeta):
"""
Holds an interable 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.
"""
CHOICES = list()
@classmethod