Model CharFiled with choices attribute mapped to regular Serializer CharField instead of ChoicesField when editable is set to False #8511
-
As I understand, model |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hi! This is by design. A |
Beta Was this translation helpful? Give feedback.
-
The problem with the current implementation is that the corresponding schema (for example, OpenAPI) for the model field does not describe the possible values correctly. This makes the schema a bit less useful when it comes to describing fields returned via GET requests, for example. So, although @yyyyyyyan's argument above is valid, it is missing the issue with the schema:
|
Beta Was this translation helpful? Give feedback.
Hi! This is by design. A
ChoiceField
is a field that can accept a value out of a limited set of choices [1]. If your field is not editable, Django assumes it's not supposed to be set [2], so the field won't show up in the admin or any ModelForm. With DRF and serializers it's the same! Since it's not supposed to be set to any value, it doesn't make sense to use aChoiceField
, because there's no need for validation.