mirror of
https://github.com/django/django.git
synced 2025-07-24 05:36:15 +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
|
@ -298,16 +298,23 @@ Model style
|
|||
* Any custom methods
|
||||
|
||||
* If ``choices`` is defined for a given model field, define each choice as a
|
||||
list of tuples, with an all-uppercase name as a class attribute on the model.
|
||||
mapping, with an all-uppercase name as a class attribute on the model.
|
||||
Example::
|
||||
|
||||
class MyModel(models.Model):
|
||||
DIRECTION_UP = "U"
|
||||
DIRECTION_DOWN = "D"
|
||||
DIRECTION_CHOICES = [
|
||||
(DIRECTION_UP, "Up"),
|
||||
(DIRECTION_DOWN, "Down"),
|
||||
]
|
||||
DIRECTION_CHOICES = {
|
||||
DIRECTION_UP: "Up",
|
||||
DIRECTION_DOWN: "Down",
|
||||
}
|
||||
|
||||
Alternatively, consider using :ref:`field-choices-enum-types`::
|
||||
|
||||
class MyModel(models.Model):
|
||||
class Direction(models.TextChoices):
|
||||
UP = U, "Up"
|
||||
DOWN = D, "Down"
|
||||
|
||||
Use of ``django.conf.settings``
|
||||
===============================
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue