summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorT. Franzel <tfranzel@users.noreply.github.com>2023-03-11 00:34:13 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-03-21 19:44:41 +0100
commita2eaea8f22305b57dff3ab13add2e2887287bb6f (patch)
treea2f1acee503899e52a583572a46aeee0d1a5432c /docs
parent051d5944f86400b9b3476db60bc73de7e9964810 (diff)
Fixed #34388 -- Allowed using choice enumeration types directly on model and form fields.
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/forms/fields.txt7
-rw-r--r--docs/ref/models/fields.txt11
-rw-r--r--docs/releases/5.0.txt8
-rw-r--r--docs/topics/db/models.txt2
4 files changed, 21 insertions, 7 deletions
diff --git a/docs/ref/forms/fields.txt b/docs/ref/forms/fields.txt
index 317a955a15..7d975a74d5 100644
--- a/docs/ref/forms/fields.txt
+++ b/docs/ref/forms/fields.txt
@@ -431,7 +431,7 @@ For each field, we describe the default widget used if you don't specify
.. attribute:: choices
Either an :term:`iterable` of 2-tuples to use as choices for this
- field, :ref:`enumeration <field-choices-enum-types>` choices, or a
+ field, :ref:`enumeration type <field-choices-enum-types>`, or a
callable that returns such an iterable. This argument accepts the same
formats as the ``choices`` argument to a model field. See the
:ref:`model field reference documentation on choices <field-choices>`
@@ -439,6 +439,11 @@ For each field, we describe the default widget used if you don't specify
time the field's form is initialized, in addition to during rendering.
Defaults to an empty list.
+ .. versionchanged:: 5.0
+
+ Support for using :ref:`enumeration types <field-choices-enum-types>`
+ directly in the ``choices`` was added.
+
``DateField``
-------------
diff --git a/docs/ref/models/fields.txt b/docs/ref/models/fields.txt
index c1267507b2..447668bbc5 100644
--- a/docs/ref/models/fields.txt
+++ b/docs/ref/models/fields.txt
@@ -210,7 +210,7 @@ choices in a concise way::
year_in_school = models.CharField(
max_length=2,
- choices=YearInSchool.choices,
+ choices=YearInSchool,
default=YearInSchool.FRESHMAN,
)
@@ -235,8 +235,7 @@ modifications:
* A ``.label`` property is added on values, to return the human-readable name.
* A number of custom properties are added to the enumeration classes --
``.choices``, ``.labels``, ``.values``, and ``.names`` -- to make it easier
- to access lists of those separate parts of the enumeration. Use ``.choices``
- as a suitable value to pass to :attr:`~Field.choices` in a field definition.
+ to access lists of those separate parts of the enumeration.
.. warning::
@@ -276,7 +275,7 @@ Django provides an ``IntegerChoices`` class. For example::
HEART = 3
CLUB = 4
- suit = models.IntegerField(choices=Suit.choices)
+ suit = models.IntegerField(choices=Suit)
It is also possible to make use of the `Enum Functional API
<https://docs.python.org/3/library/enum.html#functional-api>`_ with the caveat
@@ -320,6 +319,10 @@ There are some additional caveats to be aware of:
__empty__ = _("(Unknown)")
+.. versionchanged:: 5.0
+
+ Support for using enumeration types directly in the ``choices`` was added.
+
``db_column``
-------------
diff --git a/docs/releases/5.0.txt b/docs/releases/5.0.txt
index 7dee6c4575..f5a5c568bc 100644
--- a/docs/releases/5.0.txt
+++ b/docs/releases/5.0.txt
@@ -167,7 +167,9 @@ File Uploads
Forms
~~~~~
-* ...
+* :attr:`.ChoiceField.choices` now accepts
+ :ref:`Choices classes <field-choices-enum-types>` directly instead of
+ requiring expansion with the ``choices`` attribute.
Generic Views
~~~~~~~~~~~~~
@@ -208,6 +210,10 @@ Models
of ``ValidationError`` raised during
:ref:`model validation <validating-objects>`.
+* :attr:`.Field.choices` now accepts
+ :ref:`Choices classes <field-choices-enum-types>` directly instead of
+ requiring expansion with the ``choices`` attribute.
+
Requests and Responses
~~~~~~~~~~~~~~~~~~~~~~
diff --git a/docs/topics/db/models.txt b/docs/topics/db/models.txt
index fc0c927270..33a515f14f 100644
--- a/docs/topics/db/models.txt
+++ b/docs/topics/db/models.txt
@@ -211,7 +211,7 @@ ones:
class Runner(models.Model):
MedalType = models.TextChoices("MedalType", "GOLD SILVER BRONZE")
name = models.CharField(max_length=60)
- medal = models.CharField(blank=True, choices=MedalType.choices, max_length=10)
+ medal = models.CharField(blank=True, choices=MedalType, max_length=10)
Further examples are available in the :ref:`model field reference
<field-choices>`.