#31262: Support dictionaries in Field.choices for named groups.
-------------------------------------+-------------------------------------
Reporter: Tom Forbes | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):
* component: Forms => Database layer (models, ORM)
* version: => master
* stage: Unreviewed => Accepted
Old description:
> The Django documentation gives this example for creating named groups of
> choices:
>
> {{{
> MEDIA_CHOICES = [
> ('Audio', (
> ('vinyl', 'Vinyl'),
> ('cd', 'CD'),
> )
> ),
> ('Video', (
> ('vhs', 'VHS Tape'),
> ('dvd', 'DVD'),
> )
> ),
> ('unknown', 'Unknown'),
> ]
> }}}
>
> With Python 3.7 (and implicitly in CPython 3.6) dictionaries are ordered,
> meaning this syntax could be replaced by the cleaner and easier to parse:
>
> {{{
> {
> "Audio": (
> ('vinyl', 'Vinyl'),
> ('cd', 'CD'),
> ),
> "Video": (
> ('vhs', 'VHS Tape'),
> ('dvd', 'DVD'),
> ),
> "unknown": "Unknown"
> }
> }}}
>
> Once 3.7 is the lowest supported version we should document that this is
> supported, and ensure that it works correctly.
New description:
The Django documentation gives this example for creating named groups of
choices:
{{{
MEDIA_CHOICES = [
('Audio', (
('vinyl', 'Vinyl'),
('cd', 'CD'),
)
),
('Video', (
('vhs', 'VHS Tape'),
('dvd', 'DVD'),
)
),
('unknown', 'Unknown'),
]
}}}
With Python 3.7 (and implicitly in CPython 3.6) dictionaries are ordered,
meaning this syntax could be replaced by the cleaner and easier to parse:
{{{
{
"Audio": (
('vinyl', 'Vinyl'),
('cd', 'CD'),
),
"Video": (
('vhs', 'VHS Tape'),
('dvd', 'DVD'),
),
"unknown": "Unknown"
}
}}}
Once 3.7 is the lowest supported version we should document that this is
supported, and ensure that it works correctly.
--
Comment:
Agreed, we can officially add this even in Django 3.1, because we've
already made a decision to assume that dictionaries preserve ordering (see
#30159 and [https://github.com/django/django/pull/10894 a short
discussion]).
--
Ticket URL: <https://code.djangoproject.com/ticket/31262#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/061.5cd197a7b51625b1ff08252c44b02ad8%40djangoproject.com.