| | 174 | |
| | 175 | The first element in each tuple is the value that will be stored in the database, the second |
| | 176 | element will be displayed by the admin interface, or in a ModelChoiceField. Given an instance |
| | 177 | of a model object, the display value for a choices field can be accessed using the ``get_FOO_display`` |
| | 178 | method. For example:: |
| | 179 | |
| | 180 | from django.db import models |
| | 181 | |
| | 182 | class Person(models.Model): |
| | 183 | GENDER_CHOICES = ( |
| | 184 | ('M', 'Male'), |
| | 185 | ('F', 'Female'), |
| | 186 | ) |
| | 187 | name = models.CharField(max_length=60) |
| | 188 | gender = models.CharField(max_length=2, choices=GENDER_CHOICES) |
| | 189 | |
| | 190 | p = Person(name="Fred Flinstone", gender="M") |
| | 191 | p.save() |
| | 192 | p.gender # Returns 'M' |
| | 193 | p.get_gender_display() # returns 'Male' |