mirror of
https://github.com/django/django.git
synced 2025-10-26 15:16:09 +00:00
Added meta.Admin list_select_related option, which specifies to use select_related in the change-list query
git-svn-id: http://code.djangoproject.com/svn/django/trunk@1092 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -135,17 +135,20 @@ def change_list(request, app_label, module_name):
|
||||
f = lookup_opts.get_field(order_field)
|
||||
rel_ordering = f.rel.to.ordering and f.rel.to.ordering[0] or f.rel.to.pk.column
|
||||
lookup_order_field = '%s.%s' % (f.rel.to.db_table, rel_ordering)
|
||||
# Use select_related if one of the list_display options is a field with a
|
||||
# relationship.
|
||||
for field_name in lookup_opts.admin.list_display:
|
||||
try:
|
||||
f = lookup_opts.get_field(field_name)
|
||||
except meta.FieldDoesNotExist:
|
||||
pass
|
||||
else:
|
||||
if isinstance(f.rel, meta.ManyToOne):
|
||||
lookup_params['select_related'] = True
|
||||
break
|
||||
if lookup_opts.admin.list_select_related:
|
||||
lookup_params['select_related'] = True
|
||||
else:
|
||||
# Use select_related if one of the list_display options is a field with
|
||||
# a relationship.
|
||||
for field_name in lookup_opts.admin.list_display:
|
||||
try:
|
||||
f = lookup_opts.get_field(field_name)
|
||||
except meta.FieldDoesNotExist:
|
||||
pass
|
||||
else:
|
||||
if isinstance(f.rel, meta.ManyToOne):
|
||||
lookup_params['select_related'] = True
|
||||
break
|
||||
lookup_params['order_by'] = ((order_type == 'desc' and '-' or '') + lookup_order_field,)
|
||||
if lookup_opts.admin.search_fields and query:
|
||||
or_queries = []
|
||||
|
||||
Reference in New Issue
Block a user