Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Jannis Leidel authored April 22, 2011
1  django/db/models/query.py
@@ -403,6 +403,7 @@ def latest(self, field_name=None):
403 403
                 "Cannot change a query once a slice has been taken."
404 404
         obj = self._clone()
405 405
         obj.query.set_limits(high=1)
  406
+        obj.query.clear_ordering()
406 407
         obj.query.add_ordering('-%s' % latest_by)
407 408
         return obj.get()
408 409
 
3  tests/modeltests/get_latest/tests.py
@@ -43,6 +43,9 @@ def test_latest(self):
43 43
             a3,
44 44
         )
45 45
 
  46
+        # Ensure that latest() overrides any other ordering specified on the query. Refs #11283.
  47
+        self.assertEqual(Article.objects.order_by('id').latest(), a4)
  48
+
46 49
     def test_latest_manual(self):
47 50
         # You can still use latest() with a model that doesn't have
48 51
         # "get_latest_by" set -- just pass in the field name manually.

0 notes on commit a845eba

Please sign in to comment.
Something went wrong with that request. Please try again.