Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • 2
    Well that is silly. All I needed to do was put a list() in front of it? Crazy. Thanks! For extra karma: Can anyone explain why list() is needed and why it doesn't make the query to start? Commented Jun 14, 2011 at 0:54
  • 1
    Well when you index into a queryset, it thinks you just want a single item from that queryset, so it doesn't perform a query for the entire thing, it just does a single query for the single item you want. But yes, I can see how it would seem pretty weird :( Commented Jun 14, 2011 at 0:56
  • 1
    Also you might consider Car.objects.all() instead of filter to get all the objects from the database. Commented Jun 14, 2011 at 1:30
  • The only unclear thing here is that if the result is sorted or not. I mean, if I give the id__ins in (3,1,2) order, do I get it in this exact order or standard ascending ids? Commented Nov 26, 2018 at 19:45
  • 1
    @ErayErdin no, order is not preserved. Django's "in" lookup transforms to SQL "WHERE ... IN ..." clause. Commented Oct 20, 2021 at 17:49