Allow to reset ordering by calling order_by() with no arguments

This commit is contained in:
Thomas Steinacher 2013-06-18 18:31:24 -07:00
commit 5e787404f5
2 changed files with 3 additions and 2 deletions

View file

@ -21,6 +21,7 @@ Differences between Mongomallard and Mongoengine
* `_get_changed_fields()` / `_changed_fields` returns a set
* Simplified `EmailField` email regex to be more compatible
* Assigning invalid types (e.g. an invalid string to `IntField`) raises immediately a `ValueError`
* `order_by()` without an argument resets the ordering (no ordering will be applied)
Untested / not implemented yet:
-----

View file

@ -53,7 +53,7 @@ class QuerySet(object):
self._initial_query = {}
self._where_clause = None
self._loaded_fields = QueryFieldList()
self._ordering = []
self._ordering = None
self._snapshot = False
self._timeout = True
self._class_check = True
@ -1211,7 +1211,7 @@ class QuerySet(object):
if self._ordering:
# Apply query ordering
self._cursor_obj.sort(self._ordering)
elif self._document._meta['ordering']:
elif self._ordering == None and self._document._meta['ordering']:
# Otherwise, apply the ordering from the document model
order = self._get_order_by(self._document._meta['ordering'])
self._cursor_obj.sort(order)