Loading django/db/models/sql/compiler.py +4 −2 Original line number Diff line number Diff line Loading @@ -261,8 +261,10 @@ class SQLCompiler(object): # on verbatim. table, col = col.split('.', 1) order_by.append(( OrderBy(RawSQL('%s.%s' % (self.quote_name_unless_alias(table), col), [])), False)) OrderBy( RawSQL('%s.%s' % (self.quote_name_unless_alias(table), col), []), descending=descending ), False)) continue if not self.query._extra or col not in self.query._extra: Loading tests/ordering/tests.py +20 −0 Original line number Diff line number Diff line Loading @@ -166,6 +166,26 @@ class OrderingTests(TestCase): 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): """ Ensure that 'pk' works as an ordering option in Meta. Loading Loading
django/db/models/sql/compiler.py +4 −2 Original line number Diff line number Diff line Loading @@ -261,8 +261,10 @@ class SQLCompiler(object): # on verbatim. table, col = col.split('.', 1) order_by.append(( OrderBy(RawSQL('%s.%s' % (self.quote_name_unless_alias(table), col), [])), False)) OrderBy( RawSQL('%s.%s' % (self.quote_name_unless_alias(table), col), []), descending=descending ), False)) continue if not self.query._extra or col not in self.query._extra: Loading
tests/ordering/tests.py +20 −0 Original line number Diff line number Diff line Loading @@ -166,6 +166,26 @@ class OrderingTests(TestCase): 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): """ Ensure that 'pk' works as an ordering option in Meta. Loading