Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #6957 -- Removed a stray reference to QuerySet._select_related …

…and added

a way to copy the select_related() settings from an existing queryset.


git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@7425 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit c934beea01b62ae0daa3ee09f1bad3fac835b019 1 parent 81b3043
@malcolmt malcolmt authored
Showing with 8 additions and 2 deletions.
  1. +1 −2  django/contrib/admin/views/main.py
  2. +7 −0 django/db/models/query.py
View
3  django/contrib/admin/views/main.py
@@ -750,8 +750,7 @@ def construct_search(field_name):
for bit in self.query.split():
or_queries = [models.Q(**{construct_search(field_name): bit}) for field_name in self.lookup_opts.admin.search_fields]
other_qs = QuerySet(self.model)
- if qs._select_related:
- other_qs = other_qs.select_related()
+ other_qs.dup_select_related(qs)
other_qs = other_qs.filter(reduce(operator.or_, or_queries))
qs = qs & other_qs
View
7 django/db/models/query.py
@@ -402,6 +402,13 @@ def select_related(self, *fields, **kwargs):
obj.query.max_depth = depth
return obj
+ def dup_select_related(self, other):
+ """
+ Copies the related selection status from the queryset 'other' to the
+ current queryset.
+ """
+ self.query.select_related = other.query.select_related
+
def order_by(self, *field_names):
"""Returns a new QuerySet instance with the ordering changed."""
assert self.query.can_filter(), \
Please sign in to comment.
Something went wrong with that request. Please try again.