{{{#!python
from django import forms
from .models import Animal
class AnimalForm(forms.Form):
animal_select = forms.ModelChoiceField(
queryset=Animal.objects.all(),
required=False,
)
animal_radio = forms.ModelChoiceField(
queryset=Animal.objects.all(),
required=False,
widget=forms.RadioSelect()
)
}}}
Since Django v3.1, the field using the RadioSelect widget no longer
displays the empty option.
I've tested it with the following versions:
3.0 works
3.0.12 works
3.1 broken
3.1.6 broken
3.2a1 broken
I can't find anything in the docs or the v3.1 release notes
(https://docs.djangoproject.com/en/dev/releases/3.1/#forms) to explain the
change.
--
Ticket URL: <https://code.djangoproject.com/ticket/32434>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* Attachment "Screen Shot 2021-02-06 at 2.25.47 pm.png" added.
Example of how the fileds are rendered
* status: new => closed
* resolution: => invalid
Comment:
An empty option for `RadioSelect()` without `blank=True` in Django < 3.1
was a bug (see #26813 and da79ee472d803963dc3ea81ee67767dc06068aac).
That's why release notes are not included. You can add `blank=True` to
restore an empty option.
--
Ticket URL: <https://code.djangoproject.com/ticket/32434#comment:1>
* resolution: invalid => wontfix
--
Ticket URL: <https://code.djangoproject.com/ticket/32434#comment:2>