Hi On Mon, Jun 28, 2010 at 4:37 PM, Jeff <jeffreychar...@gmail.com> wrote: > Hi, > > I have a question concerning some queryset behaviour in Django 1.1. > > In this example, I have an article model that can contain 1 or more > authors who are users registered through Django's auth system. > > I get the following output when playing around with an article in a > shell where I have three authors: > >>>> article.authors.all() > [<User: colin>, <User: blake>, <User: jeff>] >>>> article.authors.all()[0] > <User: jeff> >>>> article.authors.all()[1] > <User: blake> >>>> article.authors.all()[2] > <User: jeff> >>>> article.authors.all()[0:1] > [<User: jeff>] >>>> article.authors.all()[1:2] > [<User: blake>] >>>> article.authors.all()[2:3] > [<User: jeff>] > > I'm curious why article.authors.all()[0] does not return <User: colin> > and instead returns <User: jeff>. I'm also curious as to why <User: > jeff> appears twice when slicing queries and it doesn't when > requesting all results. > > Thank you in advance for your time! >
Simple... User does not have a default ordering, therefore the database is free to return the results in random order (the order may even be different for subsequent queries as you have seen) You should add an .order_by() clause if you need a stable ordering of Users, f.e. User.objects.order_by('username') -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@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.