Ticket #10348: 10348_with-none-and-explicit-select-related.diff

File 10348_with-none-and-explicit-select-related.diff, 2.1 KB (added by mrts, 16 years ago)

Add None and explicitly select the related fields when False

  • django/contrib/admin/validation.py

     
    127127                continue
    128128            get_field(cls, model, opts, 'ordering[%d]' % idx, field)
    129129
    130     # list_select_related = False
    131130    # save_as = False
    132131    # save_on_top = False
    133     for attr in ('list_select_related', 'save_as', 'save_on_top'):
     132    for attr in ('save_as', 'save_on_top'):
    134133        if not isinstance(getattr(cls, attr), bool):
    135134            raise ImproperlyConfigured("'%s.%s' should be a boolean."
    136135                    % (cls.__name__, attr))
    137136
     137    # list_select_related = True, False, None
     138    if (not isinstance(cls.list_select_related, bool) and
     139            cls.list_select_related is not None):
     140        raise ImproperlyConfigured("'%s.list_select_related' should "
     141                "be a boolean or None." % cls.__name__)
    138142
     143
    139144    # inlines = []
    140145    if hasattr(cls, 'inlines'):
    141146        check_isseq(cls, 'inlines', cls.inlines)
  • django/contrib/admin/views/main.py

     
    200200        # with a relationship.
    201201        if self.list_select_related:
    202202            qs = qs.select_related()
     203        elif self.list_select_related is None:
     204            pass
    203205        else:
     206            select_related = []
    204207            for field_name in self.list_display:
    205208                try:
    206209                    f = self.lookup_opts.get_field(field_name)
     
    208211                    pass
    209212                else:
    210213                    if isinstance(f.rel, models.ManyToOneRel):
    211                         qs = qs.select_related()
    212                         break
     214                        select_related.append(field_name)
     215            if select_related:
     216                qs = qs.select_related(*select_related)
    213217
    214218        # Set ordering.
    215219        if self.order_field:
Back to Top