Opened 7 years ago
Closed 7 years ago
#29247 closed Bug (fixed)
A custom blank value in model field choices doesn't work when using named groups
Reported by: | orlnub123 | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | choices |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
While sifting through the source code to understand the internals for a package I'm making, I stumbled upon what looked like a bug.
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 here.
Change History (3)
comment:1 by , 7 years ago
Summary: | Fix choices ignoring the defined blank value → Choices ignoring the defined blank value |
---|
comment:2 by , 7 years ago
Component: | Forms → Database layer (models, ORM) |
---|---|
Patch needs improvement: | set |
Summary: | Choices ignoring the defined blank value → A custom blank value in model field choices doesn't work when using named groups |
Triage Stage: | Unreviewed → Accepted |
comment:3 by , 7 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
In 2142009: