summaryrefslogtreecommitdiff
path: root/docs/topics
diff options
context:
space:
mode:
authorNick Pope <nick@nickpope.me.uk>2023-08-31 02:57:40 +0100
committerGitHub <noreply@github.com>2023-08-30 22:57:40 -0300
commit500e01073adda32d5149624ee9a5cb7aa3d3583f (patch)
treef9416872a811aa39646deaf002414e0a7841b6d1 /docs/topics
parent68a8996bdfce2d191decd7b1c1a2b9fdea8e4b2f (diff)
Fixed #31262 -- Added support for mappings on model fields and ChoiceField's choices.
Diffstat (limited to 'docs/topics')
-rw-r--r--docs/topics/db/managers.txt8
-rw-r--r--docs/topics/db/models.txt10
-rw-r--r--docs/topics/forms/modelforms.txt10
3 files changed, 12 insertions, 16 deletions
diff --git a/docs/topics/db/managers.txt b/docs/topics/db/managers.txt
index 047d02ebae..61de153898 100644
--- a/docs/topics/db/managers.txt
+++ b/docs/topics/db/managers.txt
@@ -154,9 +154,7 @@ For example::
class Person(models.Model):
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
- role = models.CharField(
- max_length=1, choices=[("A", _("Author")), ("E", _("Editor"))]
- )
+ role = models.CharField(max_length=1, choices={"A": _("Author"), "E": _("Editor")})
people = models.Manager()
authors = AuthorManager()
editors = EditorManager()
@@ -259,9 +257,7 @@ custom ``QuerySet`` if you also implement them on the ``Manager``::
class Person(models.Model):
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
- role = models.CharField(
- max_length=1, choices=[("A", _("Author")), ("E", _("Editor"))]
- )
+ role = models.CharField(max_length=1, choices={"A": _("Author"), "E": _("Editor")})
people = PersonManager()
This example allows you to call both ``authors()`` and ``editors()`` directly from
diff --git a/docs/topics/db/models.txt b/docs/topics/db/models.txt
index 33a515f14f..cc6c1f5298 100644
--- a/docs/topics/db/models.txt
+++ b/docs/topics/db/models.txt
@@ -185,11 +185,11 @@ ones:
class Person(models.Model):
- SHIRT_SIZES = [
- ("S", "Small"),
- ("M", "Medium"),
- ("L", "Large"),
- ]
+ SHIRT_SIZES = {
+ "S": "Small",
+ "M": "Medium",
+ "L": "Large",
+ }
name = models.CharField(max_length=60)
shirt_size = models.CharField(max_length=1, choices=SHIRT_SIZES)
diff --git a/docs/topics/forms/modelforms.txt b/docs/topics/forms/modelforms.txt
index 7f3c042f30..fbd5695c17 100644
--- a/docs/topics/forms/modelforms.txt
+++ b/docs/topics/forms/modelforms.txt
@@ -173,11 +173,11 @@ Consider this set of models::
from django.db import models
from django.forms import ModelForm
- TITLE_CHOICES = [
- ("MR", "Mr."),
- ("MRS", "Mrs."),
- ("MS", "Ms."),
- ]
+ TITLE_CHOICES = {
+ "MR": "Mr.",
+ "MRS": "Mrs.",
+ "MS": "Ms.",
+ }
class Author(models.Model):