Improve ChoiceField.choices documentation #7835
Replies: 2 comments
-
You can find choice values and display values in the response from I would say that serializing choice field values to If your particular use-case requires |
Beta Was this translation helpful? Give feedback.
-
@denolehov is correct. The I've gone into more detail in #6854 (comment), but in short, it would be nice if there was some construct that differentiated DB values, API representation, and display values. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
i just now stumbled upon that the
ChoiceField
accepts the choices as tuples(value, display_name)
like documented here. As in this issue #4082, i was very surprised that the representation is thevalue
not thedisplay_name
provided in the choices.So:
I'd expect the
display_name
as the representation for a givenvalue
why else should i define thedisplay_name
then? The issue mentioned above was briefly answered with a quote form the django docs which, in my eyes, would point towards my expected behavior.Especially if your API serves a detached frontend app. This app would need the choices-dict too for the correct display of the possible abstract values. Thus leading to code duplication.
Beta Was this translation helpful? Give feedback.
All reactions