=== modified file 'django/db/models/fields/__init__.py'
|
|
|
|
| 294 | 294 | |
| 295 | 295 | def get_choices(self, include_blank=True, blank_choice=BLANK_CHOICE_DASH): |
| 296 | 296 | "Returns a list of tuples used as SelectField choices for this field." |
| 297 | | first_choice = include_blank and blank_choice or [] |
| | 297 | first_choice = include_blank and self.blank and blank_choice or [] |
| 298 | 298 | if self.choices: |
| 299 | 299 | return first_choice + list(self.choices) |
| 300 | 300 | rel_model = self.rel.to |
=== modified file 'tests/modeltests/choices/models.py'
|
|
|
|
| 23 | 23 | def __str__(self): |
| 24 | 24 | return self.name |
| 25 | 25 | |
| | 26 | CHOICES = ( |
| | 27 | (0, 'State A'), |
| | 28 | (1, 'State B'), |
| | 29 | ) |
| | 30 | |
| | 31 | |
| | 32 | class ChoiceableModel(models.Model): |
| | 33 | emptynotallowed = models.CharField(maxlength=1, choices=CHOICES) |
| | 34 | emptyallowed = models.CharField(maxlength=1, choices=CHOICES, null=True, blank=True) |
| | 35 | defaultemptynotallowed = models.CharField(maxlength=1, choices=CHOICES, default=2) |
| | 36 | defaultemptyallowed = models.CharField(maxlength=1, choices=CHOICES, null=True, blank=True, default=2) |
| | 37 | |
| 26 | 38 | __test__ = {'API_TESTS':""" |
| 27 | 39 | >>> a = Person(name='Adrian', gender='M') |
| 28 | 40 | >>> a.save() |
| … |
… |
|
| 36 | 48 | 'Male' |
| 37 | 49 | >>> s.get_gender_display() |
| 38 | 50 | 'Female' |
| | 51 | >>> ChoiceableModel._meta.fields[1].get_choices() |
| | 52 | [(0, 'State A'), (1, 'State B')] |
| | 53 | >>> ChoiceableModel._meta.fields[2].get_choices() |
| | 54 | [('', '---------'), (0, 'State A'), (1, 'State B')] |
| | 55 | >>> ChoiceableModel._meta.fields[3].get_choices() |
| | 56 | [(0, 'State A'), (1, 'State B')] |
| | 57 | >>> ChoiceableModel._meta.fields[4].get_choices() |
| | 58 | [('', '---------'), (0, 'State A'), (1, 'State B')] |
| 39 | 59 | """} |
=== modified file 'tests/modeltests/manipulators/models.py'
|
|
|
|
| 54 | 54 | |
| 55 | 55 | # Attempt to create an Album with an invalid musician. |
| 56 | 56 | >>> man.get_validation_errors(MultiValueDict({'name': ['Sallies Fforth'], 'musician': ['foo']})) |
| 57 | | {'musician': ["Select a valid choice; 'foo' is not in ['', '1']."]} |
| | 57 | {'musician': ["Select a valid choice; 'foo' is not in ['1']."]} |
| 58 | 58 | |
| 59 | 59 | # Attempt to create an Album with an invalid release_date. |
| 60 | 60 | >>> man.get_validation_errors(MultiValueDict({'name': ['Sallies Fforth'], 'musician': ['1'], 'release_date': 'today'})) |