~ubuntu-branches/ubuntu/raring/python-django/raring

« back to all changes in this revision

Viewing changes to docs/ref/models/fields.txt

  • Committer: Package Import Robot
  • Author(s): Raphaël Hertzog
  • Date: 2012-08-02 10:44:02 UTC
  • mfrom: (1.1.17) (4.4.20 sid)
  • Revision ID: package-import@ubuntu.com-20120802104402-x26ethgm9s21la1y
Tags: 1.4.1-1
* New upstream security and maintenance release. Closes: #683364
  Fixes: CVE-2012-3442 CVE-2012-3443 CVE-2012-3444
* Drop 01_disable_broken_test.diff and 04_hyphen-manpage.diff which
  have been merged upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
103
103
The choices list can be defined either as part of your model class::
104
104
 
105
105
    class Foo(models.Model):
106
 
        GENDER_CHOICES = (
107
 
            ('M', 'Male'),
108
 
            ('F', 'Female'),
 
106
        YEAR_IN_SCHOOL_CHOICES = (
 
107
            ('FR', 'Freshman'),
 
108
            ('SO', 'Sophomore'),
 
109
            ('JR', 'Junior'),
 
110
            ('SR', 'Senior'),
 
111
            ('GR', 'Graduate'),
109
112
        )
110
 
        gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
 
113
        year_in_school = models.CharField(max_length=2, choices=YEAR_IN_SCHOOL_CHOICES)
111
114
 
112
115
or outside your model class altogether::
113
116
 
114
 
    GENDER_CHOICES = (
115
 
        ('M', 'Male'),
116
 
        ('F', 'Female'),
 
117
    YEAR_IN_SCHOOL_CHOICES = (
 
118
        ('FR', 'Freshman'),
 
119
        ('SO', 'Sophomore'),
 
120
        ('JR', 'Junior'),
 
121
        ('SR', 'Senior'),
 
122
        ('GR', 'Graduate'),
117
123
    )
118
124
    class Foo(models.Model):
119
 
        gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
 
125
        year_in_school = models.CharField(max_length=2, choices=YEAR_IN_SCHOOL_CHOICES)
120
126
 
121
127
You can also collect your available choices into named groups that can
122
128
be used for organizational purposes::