summaryrefslogtreecommitdiff
path: root/docs/ref/forms
diff options
context:
space:
mode:
Diffstat (limited to 'docs/ref/forms')
-rw-r--r--docs/ref/forms/fields.txt5
-rw-r--r--docs/ref/forms/widgets.txt18
2 files changed, 12 insertions, 11 deletions
diff --git a/docs/ref/forms/fields.txt b/docs/ref/forms/fields.txt
index 307ebb15a2..5e42404f94 100644
--- a/docs/ref/forms/fields.txt
+++ b/docs/ref/forms/fields.txt
@@ -510,8 +510,9 @@ For each field, we describe the default widget used if you don't specify
.. versionchanged:: 5.0
- Support for using :ref:`enumeration types <field-choices-enum-types>`
- directly in the ``choices`` was added.
+ Support for mappings and using
+ :ref:`enumeration types <field-choices-enum-types>` directly in
+ ``choices`` was added.
``DateField``
-------------
diff --git a/docs/ref/forms/widgets.txt b/docs/ref/forms/widgets.txt
index efff81ddbc..f76759b254 100644
--- a/docs/ref/forms/widgets.txt
+++ b/docs/ref/forms/widgets.txt
@@ -58,11 +58,11 @@ widget on the field. In the following example, the
from django import forms
BIRTH_YEAR_CHOICES = ["1980", "1981", "1982"]
- FAVORITE_COLORS_CHOICES = [
- ("blue", "Blue"),
- ("green", "Green"),
- ("black", "Black"),
- ]
+ FAVORITE_COLORS_CHOICES = {
+ "blue": "Blue",
+ "green": "Green",
+ "black": "Black",
+ }
class SimpleForm(forms.Form):
@@ -95,7 +95,7 @@ example:
.. code-block:: pycon
>>> from django import forms
- >>> CHOICES = [("1", "First"), ("2", "Second")]
+ >>> CHOICES = {"1": "First", "2": "Second"}
>>> choice_field = forms.ChoiceField(widget=forms.RadioSelect, choices=CHOICES)
>>> choice_field.choices
[('1', 'First'), ('2', 'Second')]
@@ -458,9 +458,9 @@ foundation for custom widgets.
class DateSelectorWidget(forms.MultiWidget):
def __init__(self, attrs=None):
- days = [(day, day) for day in range(1, 32)]
- months = [(month, month) for month in range(1, 13)]
- years = [(year, year) for year in [2018, 2019, 2020]]
+ days = {day: day for day in range(1, 32)}
+ months = {month: month for month in range(1, 13)}
+ years = {year: year for year in [2018, 2019, 2020]}
widgets = [
forms.Select(attrs=attrs, choices=days),
forms.Select(attrs=attrs, choices=months),