Author: jezdez
Date: 2011-04-22 05:02:07 -0700 (Fri, 22 Apr 2011)
New Revision: 16067
Modified:
django/trunk/django/db/models/query.py
django/trunk/tests/modeltests/get_latest/tests.py
Log:
Fixed #11283 -- Made sure that latest() clears previously specified ordering in
a QuerySet. Thanks to benmoran, punteney, mk and and Julien Phalip.
Modified: django/trunk/django/db/models/query.py
===================================================================
--- django/trunk/django/db/models/query.py 2011-04-22 12:01:59 UTC (rev
16066)
+++ django/trunk/django/db/models/query.py 2011-04-22 12:02:07 UTC (rev
16067)
@@ -403,6 +403,7 @@
"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()
Modified: django/trunk/tests/modeltests/get_latest/tests.py
===================================================================
--- django/trunk/tests/modeltests/get_latest/tests.py 2011-04-22 12:01:59 UTC
(rev 16066)
+++ django/trunk/tests/modeltests/get_latest/tests.py 2011-04-22 12:02:07 UTC
(rev 16067)
@@ -43,6 +43,9 @@
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.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.