Skip to content

Include choices params even for non editable fields#9929

Open
ticosax wants to merge 1 commit intoencode:mainfrom
ticosax:choices-read-only-fields
Open

Include choices params even for non editable fields#9929
ticosax wants to merge 1 commit intoencode:mainfrom
ticosax:choices-read-only-fields

Conversation

@ticosax
Copy link
Contributor

@ticosax ticosax commented Mar 24, 2026

The choices param can be usefull to populate list of possible values and to instantiate a ChoiceField on the serializer, even when the field is non_editable.

Relevant for the live doc and the OpenAPI integration.

Description

The fix consist into moving the choices kwargs populating step, before the early return for non_editable fields.
just before:

 if isinstance(model_field, models.AutoField) or not model_field.editable:
     kwargs['read_only'] = True
     return kwargs

@ticosax ticosax force-pushed the choices-read-only-fields branch from 31c8854 to 758b6ec Compare March 24, 2026 10:07
The choices param can be usefull to populate list of possible values
and to instantiate a ChoiceField on the serializer, even when field is non_editable.

Relevant for the live doc and the OpenAPI integration.
@ticosax ticosax force-pushed the choices-read-only-fields branch from 758b6ec to fa16bbb Compare March 24, 2026 10:31
@anoop-dryad
Copy link

Please disregard my approval (I can't undo it apparently) I thought I was working on another repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants