mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-17 04:32:51 -06:00
ChoiceSet cleanup
This commit is contained in:
parent
1902ecb8ca
commit
d8be8e25a5
@ -34,16 +34,18 @@ class ChoiceSetMeta(type):
|
|||||||
return super().__new__(mcs, name, bases, attrs)
|
return super().__new__(mcs, name, bases, attrs)
|
||||||
|
|
||||||
def __call__(cls, *args, **kwargs):
|
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', ())
|
return getattr(cls, '_choices', ())
|
||||||
|
|
||||||
def __iter__(cls):
|
def __iter__(cls):
|
||||||
choices = getattr(cls, '_choices', ())
|
return iter(getattr(cls, '_choices', ()))
|
||||||
return iter(choices)
|
|
||||||
|
|
||||||
|
|
||||||
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
|
||||||
|
statically within the class as CHOICES and/or gleaned from the FIELD_CHOICES configuration parameter.
|
||||||
|
"""
|
||||||
CHOICES = list()
|
CHOICES = list()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
|
Loading…
Reference in New Issue
Block a user