ChoiceField
is incompatible with TextChoices
#8965
Unanswered
JulianOrteil
asked this question in
Potential Issue
Replies: 2 comments
-
related #8955 but need django built in feature support |
Beta Was this translation helpful? Give feedback.
0 replies
-
Can you please check if #8968 solves this? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
#8132 raised an issue in 2021 where
ChoiceField
has incorrect mappings. While I am unsure if the issue-raiser has encountered the same issue I am facing, this line of code is nonetheless causing problems for me.Take the following
TextChoices
object. When we attempt to serialize it through a serializer, the validation error"X" is not a valid choice
is thrown. This is because the value submitted to the serializer is the label, not the value.Diving into the cause, it can be seen that the following line--the one focused on in #8132--is the root cause. It fails to create a proper mapping between human-labels and database-values that exist in choice classes:
I've written a small patch to make this work for my code which use both
TextChoices
andIntegerChoices
:Which now outputs:
Beta Was this translation helpful? Give feedback.
All reactions