Ticket #7913: 7913.diff
| File 7913.diff, 2.5 kB (added by miracle2k, 6 months ago) |
|---|
-
a/django/db/models/fields/__init__.py
old new 288 288 if self.choices: 289 289 field_objs = [oldforms.SelectField] 290 290 291 params['choices'] = self. flatchoices291 params['choices'] = self.get_flatchoices() 292 292 else: 293 293 field_objs = self.get_manipulator_field_objs() 294 294 return (field_objs, params) … … 362 362 return val 363 363 364 364 def get_choices(self, include_blank=True, blank_choice=BLANK_CHOICE_DASH): 365 "Returns a list of tuples used as SelectField choices for this field." 365 """Returns choices with a default blank choices included, for use 366 as SelectField choices for this field.""" 366 367 first_choice = include_blank and blank_choice or [] 367 368 if self.choices: 368 369 return first_choice + list(self.choices) … … 376 377 def get_choices_default(self): 377 378 return self.get_choices() 378 379 380 def get_flatchoices(self, include_blank=True, blank_choice=BLANK_CHOICE_DASH): 381 "Returns flattened choices with a default blank choice included." 382 first_choice = include_blank and blank_choice or [] 383 return first_choices + list(self.flatchoices) 384 379 385 def _get_val_from_obj(self, obj): 380 386 if obj: 381 387 return getattr(obj, self.attname) … … 408 414 choices = property(_get_choices) 409 415 410 416 def _get_flatchoices(self): 417 """Flattened version of choices tuple.""" 411 418 flat = [] 412 for choice, value in self. get_choices_default():419 for choice, value in self.choices: 413 420 if type(value) in (list, tuple): 414 421 flat.extend(value) 415 422 else: 416 423 flat.append((choice,value)) 417 424 return flat 418 425 flatchoices = property(_get_flatchoices) 419 426 420 427 def save_form_data(self, instance, data): 421 428 setattr(instance, self.name, data) 422 429 -
a/tests/modeltests/choices/models.py
old new 36 36 u'Male' 37 37 >>> s.get_gender_display() 38 38 u'Female' 39 40 # 7913 41 >>> a.gender = '' 42 >>> a.get_gender_display() 43 u'' 39 44 """}
