Skip to content

Commit

Permalink
Utils: Make choiceval compatible with Django 3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
nijel committed Jun 15, 2020
1 parent 37d86c2 commit aa3b53d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion weblate/trans/templatetags/translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,13 @@ def choiceval(boundfield):
return gettext("enabled")
if not hasattr(boundfield.field, "choices"):
return value
choices = dict(boundfield.field.choices)
choices = list(boundfield.field.choices)
if choices and hasattr(choices[0][0], "value"):
# Django 3.1+ yields ModelChoiceIteratorValue
choices = {choice.value: value for choice, value in choices}
else:
# Django 3.0
choices = dict(choices)
if isinstance(value, list):
return ", ".join(choices.get(val, val) for val in value)
return choices.get(value, value)
Expand Down

0 comments on commit aa3b53d

Please sign in to comment.