Ticket #3436: 3436.diff

File 3436.diff, 1.4 KB (added by Ivan Sagalaev <Maniac@…>, 9 years ago)

Patch

  • django/db/models/fields/__init__.py

     
    287287
    288288    def get_choices(self, include_blank=True, blank_choice=BLANK_CHOICE_DASH):
    289289        "Returns a list of tuples used as SelectField choices for this field."
    290         first_choice = include_blank and blank_choice or []
     290        if include_blank:
     291            yield blank_choice[0]
    291292        if self.choices:
    292             return first_choice + list(self.choices)
     293            for choice in self.choices:
     294                yield choice
     295            return
    293296        rel_model = self.rel.to
    294         if hasattr(self.rel, 'get_related_field'):
    295             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)]
    296         else:
    297             lst = [(x._get_pk_val(), str(x)) for x in rel_model._default_manager.complex_filter(self.rel.limit_choices_to)]
    298         return first_choice + lst
     297        for x in rel_model._default_manager.complex_filter(self.rel.limit_choices_to):
     298            if hasattr(self.rel, 'get_related_field'):
     299                yield (getattr(x, self.rel.get_related_field().attname), str(x))
     300            else:
     301                yield (x._get_pk_val(), str(x))
    299302
    300303    def get_choices_default(self):
    301304        if self.radio_admin:
Back to Top