Django

Code

Ticket #4653: charfield_options.diff

File charfield_options.diff, 0.9 kB (added by Ilya Semenov <semenov@inetss.com>, 1 year ago)
  • django/db/models/fields/__init__.py

    old new  
    300300        "Returns a list of tuples used as SelectField choices for this field." 
    301301        first_choice = include_blank and blank_choice or [] 
    302302        if self.choices: 
    303             return first_choice + list(self.choices) 
     303            lst = list(self.choices) 
     304            if not self.blank or blank_choice[0][0]  in (str(x[0]) for x in lst): 
     305                return lst 
     306            return first_choice + lst 
    304307        rel_model = self.rel.to 
    305308        if hasattr(self.rel, 'get_related_field'): 
    306309            lst = [(getattr(x, self.rel.get_related_field().attname), str(x)) for x in rel_model._default_manager.complex_filter(self.rel.limit_choices_to)]