Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #11283 -- Made sure that latest() clears previously specified o…

…rdering in a QuerySet. Thanks to benmoran, punteney, mk and and Julien Phalip.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16067 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit a845eba8dded42a58d5b42bcb087b3f4bc65a26e 1 parent 59d1f82
@jezdez jezdez authored
View
1  django/db/models/query.py
@@ -403,6 +403,7 @@ def latest(self, field_name=None):
"Cannot change a query once a slice has been taken."
obj = self._clone()
obj.query.set_limits(high=1)
+ obj.query.clear_ordering()
obj.query.add_ordering('-%s' % latest_by)
return obj.get()
View
3  tests/modeltests/get_latest/tests.py
@@ -43,6 +43,9 @@ def test_latest(self):
a3,
)
+ # Ensure that latest() overrides any other ordering specified on the query. Refs #11283.
+ self.assertEqual(Article.objects.order_by('id').latest(), a4)
+
def test_latest_manual(self):
# You can still use latest() with a model that doesn't have
# "get_latest_by" set -- just pass in the field name manually.
Please sign in to comment.
Something went wrong with that request. Please try again.