App Engine Python SDK version 1.7.4 (2)
[gae.git] / python / lib / django_1_4 / tests / modeltests / choices / models.py
blobee01911573bb60ed8b02a4bcf3e5ee988393ab6e
1 """
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.
10 """
12 from django.db import models
15 GENDER_CHOICES = (
16 ('M', 'Male'),
17 ('F', 'Female'),
20 class Person(models.Model):
21 name = models.CharField(max_length=20)
22 gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
24 def __unicode__(self):
25 return self.name