mirror of
https://github.com/django/django.git
synced 2025-06-05 03:29:12 +00:00
magic-removal: Fixed subtle bug in QuerySet ordering -- now, if _order_by is an empty sequence, no ordering will be done. If it's None, it will use the model's ordering setting
git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2171 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
abd2bdba14
commit
e4112922f7
@ -69,7 +69,7 @@ class QuerySet(object):
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._filters = self.core_filters.copy()
|
self._filters = self.core_filters.copy()
|
||||||
self._order_by = () # Ordering, e.g. ('date', '-name')
|
self._order_by = None # Ordering, e.g. ('date', '-name'). If None, use model's ordering.
|
||||||
self._select_related = False # Whether to fill cache for related objects.
|
self._select_related = False # Whether to fill cache for related objects.
|
||||||
self._distinct = False # Whether the query should use SELECT DISTINCT.
|
self._distinct = False # Whether the query should use SELECT DISTINCT.
|
||||||
self._select = None # Dictionary of attname -> SQL.
|
self._select = None # Dictionary of attname -> SQL.
|
||||||
@ -135,11 +135,11 @@ class QuerySet(object):
|
|||||||
def count(self):
|
def count(self):
|
||||||
"Performs a SELECT COUNT() and returns the number of records as an integer."
|
"Performs a SELECT COUNT() and returns the number of records as an integer."
|
||||||
counter = self._clone()
|
counter = self._clone()
|
||||||
counter._order_by = []
|
counter._order_by = ()
|
||||||
counter._offset = None
|
counter._offset = None
|
||||||
counter._limit = None
|
counter._limit = None
|
||||||
counter._select_related = False
|
counter._select_related = False
|
||||||
_, sql, params = counter._get_sql_clause(True)
|
select, sql, params = counter._get_sql_clause(True)
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
cursor.execute("SELECT COUNT(*)" + sql, params)
|
cursor.execute("SELECT COUNT(*)" + sql, params)
|
||||||
return cursor.fetchone()[0]
|
return cursor.fetchone()[0]
|
||||||
@ -277,7 +277,11 @@ class QuerySet(object):
|
|||||||
|
|
||||||
# ORDER BY clause
|
# ORDER BY clause
|
||||||
order_by = []
|
order_by = []
|
||||||
for f in handle_legacy_orderlist(self._order_by or opts.ordering):
|
if self._order_by is not None:
|
||||||
|
ordering_to_use = self._order_by
|
||||||
|
else:
|
||||||
|
ordering_to_use = opts.ordering
|
||||||
|
for f in handle_legacy_orderlist(ordering_to_use):
|
||||||
if f == '?': # Special case.
|
if f == '?': # Special case.
|
||||||
order_by.append(backend.get_random_function_sql())
|
order_by.append(backend.get_random_function_sql())
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user