diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-10-14 02:17:12 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-10-14 02:17:12 +0000 |
| commit | bd2dfdf98956bfdc0d0879f68b5e4718adc5dc96 (patch) | |
| tree | 9550659b304ee8ccab025849b50c678abad0f983 /django | |
| parent | 90f2893aea6dc943c3dca88bec3c5195fb79fa03 (diff) | |
queryset-refactor: Fixed a problem with count() queries -- we were creating an
"ORDER BY" clause sometimes and that isn't accepted by PostgreSQL (and a waste
of time on other databases as well).
git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@6499 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/models/sql/query.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index c6a6997118..194d0817cd 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -161,7 +161,7 @@ class Query(object): Performs a COUNT() query using the current filter constraints. """ obj = self.clone() - obj.clear_ordering() + obj.clear_ordering(True) obj.clear_limits() obj.select_related = False if obj.distinct and len(obj.select) > 1: @@ -394,7 +394,10 @@ class Query(object): """ Returns a tuple representing the SQL elements in the "order by" clause. """ - ordering = self.order_by or self.model._meta.ordering + if self.order_by is None: + ordering = [] + else: + ordering = self.order_by or self.model._meta.ordering qn = self.quote_name_unless_alias opts = self.model._meta result = [] @@ -798,11 +801,15 @@ class Query(object): """ self.order_by.extend(ordering) - def clear_ordering(self): + def clear_ordering(self, force_empty=False): """ - Removes any ordering settings. + Removes any ordering settings. If 'force_empty' is True, there will be + no ordering in the resulting query (not even the model's default). """ - self.order_by = [] + if force_empty: + self.order_by = None + else: + self.order_by = [] def add_count_column(self): """ |
