#10742: ModelAdmin.list_select_related needs three-valued logic to support 
custom
select_related() calls
----------------------------------+-----------------------------------------
 Reporter:  mrts                  |       Owner:  nobody    
   Status:  new                   |   Milestone:  1.1       
Component:  django.contrib.admin  |     Version:  SVN       
 Keywords:                        |       Stage:  Unreviewed
Has_patch:  1                     |  
----------------------------------+-----------------------------------------
 If any of the related fields in a model is nullable, e.g.

 {{{
 class C(Base):
     a = models.ForeignKey(A, blank=True, null=True)
     b = models.ForeignKey(B)
     is_published = models.BooleanField()
 }}}

 , `select_related()` does not pull them in by default (see
 http://docs.djangoproject.com/en/dev/ref/models/querysets/#select-
 related).

 Forcing it explicitly as follows

 {{{
 class CAdmin(admin.ModelAdmin):
     list_display = ('name', 'a', 'b', 'is_published')
     list_select_related = None

     def queryset(self, request):
         qs = super(CAdmin, self).queryset(request)
         return qs.select_related('a', 'b')
 }}}

 has no effect, as `ChangeList.get_query_set()` blindly overrides it with a
 plain `select_related()` (see
 [source:django/trunk/django/contrib/admin/views/main...@10407#l201]).

 To get the desired behviour of pulling in the nullable relations in a
 single query, three-valued logic is required for
 `ModelAdmin.list_select_related`:
  * `True` -- always call `select_related()`,
  * `False` (the default) -- call `select_related()` if any of the fields
 in `list_display` is a foreign key,
  * `None` (added) -- leave the queryset alone.

 Patch attached.

 See also #10722 and http://groups.google.com/group/django-
 developers/browse_thread/thread/e1762a77979f7cbe .

-- 
Ticket URL: <http://code.djangoproject.com/ticket/10742>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to