8👍
Build a dict of the display_value: value
pairs and get the value from it:
CATEGORIES_D = {v: k for k, v in CATEGORY_CHOICES}
category = CATEGORIES_D[category]
0👍
How about this:
choices_dict = {}
for choice, value in CATEGORY_CHOICES:
choices_dict[value] = choice
category = choices_dict[category]
- [Django]-Install hstore extension for django tests
- [Django]-Define component schema with drf-spectacular for django API
- [Django]-Prevent emails from Python from being flagged as spam
- [Django]-How to combine select_related() and value()?
- [Django]-Query on manyToMany field with related_name
Source:stackexchange.com