1
0
mirror of https://github.com/django/django.git synced 2025-07-07 11:19:12 +00:00

[4.0.x] Fixed #33658 -- Doc'd ModelChoiceField.blank attribute.

Thanks Mariusz Felisiak for reviewing.

Backport of df22566748faa7bd16a9616617875e8370cbe4ee from main
This commit is contained in:
Alokik Vijay 2022-04-30 21:29:51 +05:30 committed by Mariusz Felisiak
parent 5db5c33baa
commit 256db5c048

View File

@ -1235,7 +1235,7 @@ generating choices. See :ref:`iterating-relationship-choices` for details.
are derived and which is used to validate the user's selection. It's are derived and which is used to validate the user's selection. It's
evaluated when the form is rendered. evaluated when the form is rendered.
``ModelChoiceField`` also takes two optional arguments: ``ModelChoiceField`` also takes several optional arguments:
.. attribute:: empty_label .. attribute:: empty_label
@ -1251,9 +1251,11 @@ generating choices. See :ref:`iterating-relationship-choices` for details.
# No empty label # No empty label
field2 = forms.ModelChoiceField(queryset=..., empty_label=None) field2 = forms.ModelChoiceField(queryset=..., empty_label=None)
Note that if a ``ModelChoiceField`` is required and has a default Note that no empty choice is created (regardless of the value of
initial value, no empty choice is created (regardless of the value ``empty_label``) if a ``ModelChoiceField`` is required and has a
of ``empty_label``). default initial value, or a ``widget`` is set to
:class:`~django.forms.RadioSelect` and the
:attr:`~ModelChoiceField.blank` argument is ``False``.
.. attribute:: to_field_name .. attribute:: to_field_name
@ -1291,6 +1293,13 @@ generating choices. See :ref:`iterating-relationship-choices` for details.
... ...
</select> </select>
.. attribute:: blank
When using the :class:`~django.forms.RadioSelect` widget, this optional
boolean argument determines whether an empty choice is created. By
default, ``blank`` is ``False``, in which case no empty choice is
created.
``ModelChoiceField`` also has the attribute: ``ModelChoiceField`` also has the attribute:
.. attribute:: iterator .. attribute:: iterator