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 field choices as a namedtuple by whiteinge 2 years, 1 month ago
- In page edit object links by punteney 5 years, 1 month ago
- Manager introspecting attached model by ubernostrum 5 years, 2 months ago
- Command Line Script Launcher by dakrauth 4 years, 10 months ago
- FieldsetForm by Ciantic 6 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.
#