mirror of
https://github.com/django/django.git
synced 2025-08-03 10:34:04 +00:00
Fixed #31262 -- Added support for mappings on model fields and ChoiceField's choices.
This commit is contained in:
parent
68a8996bdf
commit
500e01073a
29 changed files with 822 additions and 249 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue