~ubuntu-branches/debian/sid/python-django/sid

« back to all changes in this revision

Viewing changes to tests/choices/models.py

  • Committer: Package Import Robot
  • Author(s): Luke Faraone
  • Date: 2013-11-07 15:33:49 UTC
  • mfrom: (1.3.12)
  • Revision ID: package-import@ubuntu.com-20131107153349-e31sc149l2szs3jb
Tags: 1.6-1
* New upstream version. Closes: #557474, #724637.
* python-django now also suggests the installation of ipython,
  bpython, python-django-doc, and libgdal1.
  Closes: #636511, #686333, #704203
* Set package maintainer to Debian Python Modules Team.
* Bump standards version to 3.9.5, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""
 
2
21. Specifying 'choices' for a field
 
3
 
 
4
Most fields take a ``choices`` parameter, which should be a tuple of tuples
 
5
specifying which are the valid values for that field.
 
6
 
 
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
"""
 
11
 
 
12
from django.db import models
 
13
from django.utils.encoding import python_2_unicode_compatible
 
14
 
 
15
 
 
16
GENDER_CHOICES = (
 
17
    ('M', 'Male'),
 
18
    ('F', 'Female'),
 
19
)
 
20
 
 
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)
 
25
 
 
26
    def __str__(self):
 
27
        return self.name