ChoiceField metadata does not support grouped choices. · Issue #3101 · encode/django-rest-framework (original) (raw)
If a serialiser has a ChoiceField with grouped choices:
TYPE_CHOICES = (
('Default', (
(1, 'Option 1'),
(2, 'Option 2'),
(3, 'Option 3'))),
(4, 'Option 4'))
The OPTIONS
metadata for the field includes the choices
:
[
{
"value": "Default",
"display_name": "((1, 'Option 1'), (2, 'Option 2'), (3, 'Option 3'))"
},
{
"value": 4,
"display_name": "Option 4"
}
]
I am not certain what the behaviour should be, but something including the nested choices would be useful:
[
{
"choices": [
{
"value": 1,
"display_name": "Option 1"
},
{
"value": 2,
"display_name": "Option 2"
},
{
"value": 3,
"display_name": "Option 3"
}
],
"display_name": "Default"
},
{
"value": 4,
"display_name": "Option 4"
}
]
If this is not appropriate then a flat list of choices might be appropriate.
[
{
"value": 1,
"display_name": "Option 1"
},
{
"value": 2,
"display_name": "Option 2"
},
{
"value": 3,
"display_name": "Option 3"
},
{
"value": 4,
"display_name": "Option 4"
}
]