You the man Alex, that was the problem!

On Jun 11, 11:19 am, Alex Gaynor <alex.gay...@gmail.com> wrote:
> On Thu, Jun 11, 2009 at 11:15 AM, Tom Evans <tevans...@googlemail.com>wrote:
>
>
>
>
>
> > On Thu, 2009-06-11 at 09:04 -0700, Sean Brant wrote:
> > > If I have 2 sql queries one with a limit of 5 and the other with a
> > > limit or 6 they return there results in diffrent orders.
>
> > > Here is a example.
>
> > > >>> class Book(models.Model):
> > > >>>    title = models.CharField(max_length=150)
> > > >>>    author = models.CharField(max_length=100)
>
> > > >>> book_list_1 = Books.objects.order_by('author')[0:5]
> > > >>> book_list_2 = Books.objects.order_by('author')[0:6]
>
> > > >>> print book_list_1
> > > <<< [<Book: Book1>, <Book: Book2>, <Book: Book3>, <Book: Book4>,
> > > <Book: Book6>]
>
> > > >>> print book_list_2
> > > <<< [<Book: Book1>, <Book: Book6>, <Book: Book2>, <Book: Book3>,
> > > <Book: Book5>, <Book: Book4>]
>
> > > Very confused.
>
> > Django just returns them in the order your database engine returns them.
> > If you look at django.db.connection.queries, and run them in your db
> > shell, they will return the items in a different order. What's causing
> > that is interesting though, what db engine do you use?
>
> > Might be interesting to see the queries, and also book_list_n.values().
>
> > Cheers
>
> > Tom
>
> The cause is likely that the author for each item is equal, and there is no
> defined ordering for equal objects.  If you want a consistant ordering
> provide 2 levels or ordering, aka: order_by('author', 'other_field') with
> another field such as 'id'.
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to