Now order_by() works like queries for referencing deeper fields (replacing . with __). old: order_by('mydoc.myattr') / new: order_by('mydoc__myattr'). Closes #45

This commit is contained in:
flosch 2010-07-26 17:28:59 +02:00
parent 6791f205af
commit 21d267cb11

View File

@ -670,11 +670,13 @@ class QuerySet(object):
""" """
key_list = [] key_list = []
for key in keys: for key in keys:
if not key: continue
direction = pymongo.ASCENDING direction = pymongo.ASCENDING
if key[0] == '-': if key[0] == '-':
direction = pymongo.DESCENDING direction = pymongo.DESCENDING
if key[0] in ('-', '+'): if key[0] in ('-', '+'):
key = key[1:] key = key[1:]
key = key.replace('__', '.')
key_list.append((key, direction)) key_list.append((key, direction))
self._ordering = key_list self._ordering = key_list