1 2 3 4 5 6 7 8 9 10 11 12 13 14 | """
>>> states = Enum('OPEN', 'CLOSED')
>>> states.OPEN
0
>>> states.get_choices()
((0, 'OPEN'), (1, 'CLOSED'))
"""
class DjangoEnum(object):
def __init__(self, *string_list):
self.__dict__.update([(string, number) for (number, string)
in enumerate(string_list)])
def get_choices(self):
return tuple(enumerate(self.__dict__.keys()))
|
More like this
- Enumeration field by nail.xx 4 years, 10 months ago
- Better Django Model Field Choices by jorjun 2 years, 2 months ago
- Storing IP address ModelField as Integer, without nasty hacks.. by sleepycal 1 year, 10 months ago
- More readable Enumeration class for Django choices by achimnol 3 years, 10 months ago
- Choices helper by jacobian 3 years, 9 months ago
Comments