1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Fixed #24174 -- Fixed extra order by descending

This commit is contained in:
Josh Smeaton 2015-01-19 10:35:10 +11:00
parent 2fa2068406
commit 69c6a6868f
2 changed files with 24 additions and 2 deletions

View File

@ -261,8 +261,10 @@ class SQLCompiler(object):
# on verbatim. # on verbatim.
table, col = col.split('.', 1) table, col = col.split('.', 1)
order_by.append(( order_by.append((
OrderBy(RawSQL('%s.%s' % (self.quote_name_unless_alias(table), col), [])), OrderBy(
False)) RawSQL('%s.%s' % (self.quote_name_unless_alias(table), col), []),
descending=descending
), False))
continue continue
if not self.query._extra or col not in self.query._extra: if not self.query._extra or col not in self.query._extra:

View File

@ -166,6 +166,26 @@ class OrderingTests(TestCase):
attrgetter("headline") attrgetter("headline")
) )
def test_extra_ordering_with_table_name(self):
self.assertQuerysetEqual(
Article.objects.extra(order_by=['ordering_article.headline']), [
"Article 1",
"Article 2",
"Article 3",
"Article 4",
],
attrgetter("headline")
)
self.assertQuerysetEqual(
Article.objects.extra(order_by=['-ordering_article.headline']), [
"Article 4",
"Article 3",
"Article 2",
"Article 1",
],
attrgetter("headline")
)
def test_order_by_pk(self): def test_order_by_pk(self):
""" """
Ensure that 'pk' works as an ordering option in Meta. Ensure that 'pk' works as an ordering option in Meta.