Ticket #10348: admin_select_related.diff

File admin_select_related.diff, 1.5 KB (added by erny, 16 years ago)

new version of patch

  • django/django/contrib/admin/views/main.py

     
    198198        # Use select_related() if one of the list_display options is a field
    199199        # with a relationship.
    200200        if self.list_select_related:
    201             qs = qs.select_related()
    202         else:
    203             for field_name in self.list_display:
    204                 try:
    205                     f = self.lookup_opts.get_field(field_name)
    206                 except models.FieldDoesNotExist:
    207                     pass
    208                 else:
    209                     if isinstance(f.rel, models.ManyToOneRel):
    210                         qs = qs.select_related()
    211                         break
     201            select_related  = getattr(self.model_admin, 'select_related', None)
     202            if select_related == None:
     203                select_related = []
     204                for field_name in self.list_display:
     205                    try:
     206                        f = self.lookup_opts.get_field(field_name)
     207                    except models.FieldDoesNotExist:
     208                        pass
     209                    else:
     210                        if isinstance(f.rel, models.ManyToOneRel):
     211                            select_related.append(field_name)
     212            if select_related:
     213                qs = qs.select_related(*select_related)
    212214
    213215        # Set ordering.
    214216        if self.order_field:
Back to Top