summaryrefslogtreecommitdiff
path: root/docs/topics/db/models.txt
diff options
context:
space:
mode:
Diffstat (limited to 'docs/topics/db/models.txt')
-rw-r--r--docs/topics/db/models.txt13
1 files changed, 13 insertions, 0 deletions
diff --git a/docs/topics/db/models.txt b/docs/topics/db/models.txt
index f47490877f..0aab0bb35f 100644
--- a/docs/topics/db/models.txt
+++ b/docs/topics/db/models.txt
@@ -198,6 +198,19 @@ ones:
>>> p.get_shirt_size_display()
'Large'
+ You can also use enumeration classes to define ``choices`` in a concise
+ way::
+
+ from django.db import models
+
+ 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)
+
+ Further examples are available in the :ref:`model field reference
+ <field-choices>`.
+
:attr:`~Field.default`
The default value for the field. This can be a value or a callable
object. If callable it will be called every time a new object is