Author: mtredinnick
Date: 2007-10-23 08:34:03 -0500 (Tue, 23 Oct 2007)
New Revision: 6599

Modified:
   django/branches/queryset-refactor/django/db/models/query.py
   django/branches/queryset-refactor/tests/modeltests/ordering/models.py
Log:
queryset-refactor: Fixed an order_by() regression. It must override any
existing ordering, not append to it.


Modified: django/branches/queryset-refactor/django/db/models/query.py
===================================================================
--- django/branches/queryset-refactor/django/db/models/query.py 2007-10-23 
13:12:04 UTC (rev 6598)
+++ django/branches/queryset-refactor/django/db/models/query.py 2007-10-23 
13:34:03 UTC (rev 6599)
@@ -303,6 +303,7 @@
         assert self.query.can_filter(), \
                 "Cannot reorder a query once a slice has been taken."
         obj = self._clone()
+        obj.query.clear_ordering()
         obj.query.add_ordering(*field_names)
         return obj
 

Modified: django/branches/queryset-refactor/tests/modeltests/ordering/models.py
===================================================================
--- django/branches/queryset-refactor/tests/modeltests/ordering/models.py       
2007-10-23 13:12:04 UTC (rev 6598)
+++ django/branches/queryset-refactor/tests/modeltests/ordering/models.py       
2007-10-23 13:34:03 UTC (rev 6599)
@@ -64,4 +64,11 @@
 # don't know what order the output will be in.
 >>> Article.objects.order_by('?')
 [...]
+
+# order_by() overrides any previous ordering, so only the last one has any
+# effect.
+>>> Article.objects.order_by('id')
+[<Article: Article 1>, <Article: Article 2>, <Article: Article 3>, <Article: 
Article 4>]
+>>> Article.objects.order_by('id').order_by('-headline')
+[<Article: Article 4>, <Article: Article 3>, <Article: Article 2>, <Article: 
Article 1>]
 """}


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to