Fixed #11283 -- Made sure that latest() clears previously specified ordering 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
This commit is contained in:
parent
59d1f82634
commit
a845eba8dd
|
@ -403,6 +403,7 @@ class QuerySet(object):
|
|||
"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()
|
||||
|
||||
|
|
|
@ -43,6 +43,9 @@ class LatestTests(TestCase):
|
|||
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.
|
||||
|
|
Loading…
Reference in New Issue