Ticket #2037: 2037_2.diff
File 2037_2.diff, 2.8 KB (added by , 18 years ago) |
---|
-
django/db/models/fields/__init__.py
=== 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 or self.null) and blank_choice or [] 298 298 if self.choices: 299 299 return first_choice + list(self.choices) 300 300 rel_model = self.rel.to -
tests/modeltests/choices/models.py
=== 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 class ChoiceableModel(models.Model): 32 emptynotallowed = models.CharField(maxlength=1, choices=CHOICES) 33 emptyallowed = models.CharField(maxlength=1, choices=CHOICES, null=True, blank=True) 34 defaultemptynotallowed = models.CharField(maxlength=1, choices=CHOICES, default=2) 35 defaultemptyallowed = models.CharField(maxlength=1, choices=CHOICES, null=True, blank=True, default=2) 36 nullrelation = models.ForeignKey(Person, null=True) 37 relation = models.ForeignKey(Person, related_name='notnulrelation') 38 26 39 __test__ = {'API_TESTS':""" 27 40 >>> a = Person(name='Adrian', gender='M') 28 41 >>> a.save() … … 36 49 'Male' 37 50 >>> s.get_gender_display() 38 51 'Female' 52 >>> ChoiceableModel._meta.fields[1].get_choices() 53 [(0, 'State A'), (1, 'State B')] 54 >>> ChoiceableModel._meta.fields[2].get_choices() 55 [('', '---------'), (0, 'State A'), (1, 'State B')] 56 >>> ChoiceableModel._meta.fields[3].get_choices() 57 [(0, 'State A'), (1, 'State B')] 58 >>> ChoiceableModel._meta.fields[4].get_choices() 59 [('', '---------'), (0, 'State A'), (1, 'State B')] 60 >>> ChoiceableModel._meta.fields[5].get_choices() 61 [('', '---------'), (1, 'Adrian'), (2, 'Sara')] 62 >>> ChoiceableModel._meta.fields[6].get_choices() 63 [(1, 'Adrian'), (2, 'Sara')] 39 64 """} -
tests/modeltests/manipulators/models.py
=== 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'}))