1 2 3 4 5 6 7 8 9 10 11 | class MyChoices:
def __init__(self, **entries):
self.__dict__.update(entries)
self.choices = [ ]
for val in entries.values():
for key in entries.keys():
if entries[key] == val:
self.choices.append((val, key))
def get_choices(self):
return self.choices
|
More like this
- Model Choices Helper by pmclanahan 2 years, 3 months ago
- Model field choices as a namedtuple by whiteinge 1 year, 1 month ago
- Choices datatype for model by menendez 4 years, 1 month ago
- Django enumeration for model field choices by martinthenext 1 month, 3 weeks ago
- FieldsetForm by Ciantic 5 years, 1 month ago
Comments
Here is a similar solution which allows you to pass dictionaries to the constructor, and inserts the key/value pairs into the choice-list in the same manner they are in the dictionaries.
#