2
21. Specifying 'choices' for a field
4
Most fields take a ``choices`` parameter, which should be a tuple of tuples
5
specifying which are the valid values for that field.
7
For each field that has ``choices``, a model instance gets a
8
``get_fieldname_display()`` method, where ``fieldname`` is the name of the
9
field. This method returns the "human-readable" value of the field.
12
from django.db import models
13
from django.utils.encoding import python_2_unicode_compatible
21
@python_2_unicode_compatible
22
class Person(models.Model):
23
name = models.CharField(max_length=20)
24
gender = models.CharField(max_length=1, choices=GENDER_CHOICES)