Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added meta.Admin list_select_related option, which specifies to use s…

…elect_related in the change-list query

git-svn-id: http://code.djangoproject.com/svn/django/trunk@1092 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 181ee4ae3175f2c7dfd89dd3418dfe81cc135a51 1 parent 8ee33da
Adrian Holovaty authored November 05, 2005
25  django/contrib/admin/views/main.py
@@ -135,17 +135,20 @@ def change_list(request, app_label, module_name):
135 135
         f = lookup_opts.get_field(order_field)
136 136
         rel_ordering = f.rel.to.ordering and f.rel.to.ordering[0] or f.rel.to.pk.column
137 137
         lookup_order_field = '%s.%s' % (f.rel.to.db_table, rel_ordering)
138  
-    # Use select_related if one of the list_display options is a field with a
139  
-    # relationship.
140  
-    for field_name in lookup_opts.admin.list_display:
141  
-        try:
142  
-            f = lookup_opts.get_field(field_name)
143  
-        except meta.FieldDoesNotExist:
144  
-            pass
145  
-        else:
146  
-            if isinstance(f.rel, meta.ManyToOne):
147  
-                lookup_params['select_related'] = True
148  
-                break
  138
+    if lookup_opts.admin.list_select_related:
  139
+        lookup_params['select_related'] = True
  140
+    else:
  141
+        # Use select_related if one of the list_display options is a field with
  142
+        # a relationship.
  143
+        for field_name in lookup_opts.admin.list_display:
  144
+            try:
  145
+                f = lookup_opts.get_field(field_name)
  146
+            except meta.FieldDoesNotExist:
  147
+                pass
  148
+            else:
  149
+                if isinstance(f.rel, meta.ManyToOne):
  150
+                    lookup_params['select_related'] = True
  151
+                    break
149 152
     lookup_params['order_by'] = ((order_type == 'desc' and '-' or '') + lookup_order_field,)
150 153
     if lookup_opts.admin.search_fields and query:
151 154
         or_queries = []
3  django/core/meta/fields.py
@@ -730,7 +730,7 @@ def __init__(self, to, field_name, num_in_admin=0, edit_inline=False,
730 730
 
731 731
 class Admin:
732 732
     def __init__(self, fields=None, js=None, list_display=None, list_filter=None, date_hierarchy=None,
733  
-        save_as=False, ordering=None, search_fields=None, save_on_top=False):
  733
+        save_as=False, ordering=None, search_fields=None, save_on_top=False, list_select_related=False):
734 734
         self.fields = fields
735 735
         self.js = js or []
736 736
         self.list_display = list_display or ['__repr__']
@@ -739,6 +739,7 @@ def __init__(self, fields=None, js=None, list_display=None, list_filter=None, da
739 739
         self.save_as, self.ordering = save_as, ordering
740 740
         self.search_fields = search_fields or []
741 741
         self.save_on_top = save_on_top
  742
+        self.list_select_related = list_select_related
742 743
 
743 744
     def get_field_objs(self, opts):
744 745
         """

0 notes on commit 181ee4a

Please sign in to comment.
Something went wrong with that request. Please try again.