diff options
| author | Jacob Kaplan-Moss <jacob@jacobian.org> | 2012-06-06 11:54:26 +0200 |
|---|---|---|
| committer | Jacob Kaplan-Moss <jacob@jacobian.org> | 2012-06-06 13:55:09 +0200 |
| commit | 45d43317b7db845a7c565522b3e6e6b2dab46a64 (patch) | |
| tree | 4f945d9615587d6fedb283ec010d8a56c0e4e2e2 /docs/ref/models | |
| parent | 0a8a6b92b28fad50924a84cf2b4e1d7c5e501a1f (diff) | |
[1.4.X] Replaced documentation snippets using "gender" with less sensitive examples.
Backport of [7edf231] from master.
Diffstat (limited to 'docs/ref/models')
| -rw-r--r-- | docs/ref/models/fields.txt | 22 | ||||
| -rw-r--r-- | docs/ref/models/instances.txt | 36 |
2 files changed, 34 insertions, 24 deletions
diff --git a/docs/ref/models/fields.txt b/docs/ref/models/fields.txt index 36bf60e9ac..5062e90ebe 100644 --- a/docs/ref/models/fields.txt +++ b/docs/ref/models/fields.txt @@ -103,20 +103,26 @@ element is the human-readable name for the option. The choices list can be defined either as part of your model class:: class Foo(models.Model): - GENDER_CHOICES = ( - ('M', 'Male'), - ('F', 'Female'), + YEAR_IN_SCHOOL_CHOICES = ( + ('FR', 'Freshman'), + ('SO', 'Sophomore'), + ('JR', 'Junior'), + ('SR', 'Senior'), + ('GR', 'Graduate'), ) - gender = models.CharField(max_length=1, choices=GENDER_CHOICES) + year_in_school = models.CharField(max_length=2, choices=YEAR_IN_SCHOOL_CHOICES) or outside your model class altogether:: - GENDER_CHOICES = ( - ('M', 'Male'), - ('F', 'Female'), + YEAR_IN_SCHOOL_CHOICES = ( + ('FR', 'Freshman'), + ('SO', 'Sophomore'), + ('JR', 'Junior'), + ('SR', 'Senior'), + ('GR', 'Graduate'), ) class Foo(models.Model): - gender = models.CharField(max_length=1, choices=GENDER_CHOICES) + year_in_school = models.CharField(max_length=2, choices=YEAR_IN_SCHOOL_CHOICES) You can also collect your available choices into named groups that can be used for organizational purposes:: diff --git a/docs/ref/models/instances.txt b/docs/ref/models/instances.txt index 1f60f43c97..3b592d06dc 100644 --- a/docs/ref/models/instances.txt +++ b/docs/ref/models/instances.txt @@ -550,25 +550,29 @@ might have some of the following methods: For every field that has :attr:`~django.db.models.Field.choices` set, the object will have a ``get_FOO_display()`` method, where ``FOO`` is the name of -the field. This method returns the "human-readable" value of the field. For -example, in the following model:: +the field. This method returns the "human-readable" value of the field. - GENDER_CHOICES = ( - ('M', 'Male'), - ('F', 'Female'), - ) - class Person(models.Model): - name = models.CharField(max_length=20) - gender = models.CharField(max_length=1, choices=GENDER_CHOICES) +For example:: + + from django.db import models + + class Person(models.Model): + SHIRT_SIZES = ( + (u'S', u'Small'), + (u'M', u'Medium'), + (u'L', u'Large'), + ) + name = models.CharField(max_length=60) + shirt_size = models.CharField(max_length=2, choices=SHIRT_SIZES) -...each ``Person`` instance will have a ``get_gender_display()`` method. Example:: + :: - >>> p = Person(name='John', gender='M') - >>> p.save() - >>> p.gender - 'M' - >>> p.get_gender_display() - 'Male' + >>> p = Person(name="Fred Flintstone", shirt_size="L") + >>> p.save() + >>> p.shirt_size + u'L' + >>> p.get_shirt_size_display() + u'Large' .. method:: Model.get_next_by_FOO(\**kwargs) .. method:: Model.get_previous_by_FOO(\**kwargs) |
