From 96bc9ec79d12420a765ba210a9d8313c05b13d39 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Fri, 22 Sep 2006 13:10:46 +0000 Subject: [PATCH] Fixed #2520 -- Fixed a problem with invalid SQL being generated by admin interface in certain circumstances. Patch from favo@exoweb.net. git-svn-id: http://code.djangoproject.com/svn/django/trunk@3794 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- AUTHORS | 1 + django/contrib/admin/views/main.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/AUTHORS b/AUTHORS index 0f80baf81a..423c44fd3c 100644 --- a/AUTHORS +++ b/AUTHORS @@ -72,6 +72,7 @@ answer newbie questions, and generally made Django that much better: Jeremy Dunck Andy Dustman Clint Ecker + favo@exoweb.net gandalf@owca.info Baishampayan Ghose martin.glueck@gmail.com diff --git a/django/contrib/admin/views/main.py b/django/contrib/admin/views/main.py index 7c942ca5b8..38d64bd73b 100644 --- a/django/contrib/admin/views/main.py +++ b/django/contrib/admin/views/main.py @@ -727,6 +727,8 @@ class ChangeList(object): 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 = other_qs.filter(reduce(operator.or_, or_queries)) qs = qs & other_qs