#28502: Select widget doesn't accept non-string as value
-------------------------------------+-------------------------------------
Reporter: Nguyễn | Owner: nobody
Hồng Quân |
Type: Bug | Status: new
Component: Forms | Version: 1.11
Severity: Normal | Keywords: widget filter
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
I made a model, with `age_bracket` field, which accepts values from
choices like this:
{{{#!python
AGE_BRACKET = (
# The value in the first column will be saved in Postgres Range field,
# so the upper boundary is not counted, i.e for (18, 25) range, the
value 25
# is not counted.
((None, 18), _('Under 18')),
((18, 25), _('18 - 24')),
((25, 36), _('25 - 35')),
((36, 46), _('36 - 45')),
((46, 56), _('46 - 55')),
((46, 66), _('56 - 65')),
((66, None), _('Above 65')),
)
}}}
However, when being rendered as form, all values become empty string. This
happens since Django 1.11. In Django 1.10, it was OK.
I found the cause is the widget template ''select_option.html''
{{{#!django
<option value="{{ widget.value|stringformat:'s' }}"{% include
"django/forms/widgets/attrs.html" %}>{{ widget.label }}</option>
}}}
The `stringformat` filter turns every non-string value to empty string.
My suggestion is that, update `stringformat` so that it returns
`str(value)` if value is not a string. Is it right way to do?
--
Ticket URL: <https://code.djangoproject.com/ticket/28502>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/051.caf0118796aa8e295092f21e6b1fc645%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.