On Mon, Jun 28, 2010 at 10:37 AM, 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!
>

I'm guessing you are using PostgreSQL? And you have no ordering specified on
the authors model? This is typical behavior for that situation. These
queries pull results from the DB by using OFFSET and LIMIT...if there is no
ORDER BY in the query then the DB can (and PostgreSQL definitely will)
return "unpredictable" results for them.  See:
http://developer.postgresql.org/pgdocs/postgres/queries-limit.html

Karen
-- 
http://tracey.org/kmt/

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

Reply via email to