These lines right here:
{{{
named_groups = isinstance(choices[0][1], (list, tuple))
blank_defined = not named_groups and any(choice in ('', None) for choice,
__ in choices)
}}}
And indeed a bug it was.
The problem was that, had you defined your choices first with a group and
then later on a choice that defined the blank value, the current
implementation would skip right over it! So you would end up with having
both the default blank value and the one you've defined, which doesn't
look very pretty.
I've created a pull request on github that fixes the issue
[https://github.com/django/django/pull/9813 here.]
--
Ticket URL: <https://code.djangoproject.com/ticket/29247>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
Ticket URL: <https://code.djangoproject.com/ticket/29247#comment:1>
* needs_better_patch: 0 => 1
* stage: Unreviewed => Accepted
* component: Forms => Database layer (models, ORM)
--
Ticket URL: <https://code.djangoproject.com/ticket/29247#comment:2>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"21420096c4db78ccb8f549a29d662cff870d363c" 2142009]:
{{{
#!CommitTicketReference repository=""
revision="21420096c4db78ccb8f549a29d662cff870d363c"
Fixed #29247 -- Allowed blank model field choice to be defined in nested
choices.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29247#comment:3>