Fixes ordering with custom db field names

Closes #125
This commit is contained in:
Ross Lawley 2011-05-18 12:18:33 +01:00
parent 1781c4638b
commit 7ba40062d3
2 changed files with 18 additions and 0 deletions

View File

@ -939,6 +939,10 @@ class QuerySet(object):
if key[0] in ('-', '+'):
key = key[1:]
key = key.replace('__', '.')
try:
key = QuerySet._translate_field_name(self._document, key)
except:
pass
key_list.append((key, direction))
self._ordering = key_list

View File

@ -1746,6 +1746,20 @@ class QuerySetTest(unittest.TestCase):
Comment.drop_collection()
Post.drop_collection()
def test_order_works_with_custom_db_field_names(self):
class Number(Document):
n = IntField(db_field='number')
Number.drop_collection()
n2 = Number.objects.create(n=2)
n1 = Number.objects.create(n=1)
self.assertEqual(list(Number.objects), [n2,n1])
self.assertEqual(list(Number.objects.order_by('n')), [n1,n2])
Number.drop_collection()
class QTest(unittest.TestCase):