Do you have a single list of the IDs you want? If so, you can do something like `User.objects.get(id__in=user_ids)`. This will fetch all Users whose `id` is in some list `user_ids`.
Does that help? Happy hacking! James On Fri, Sep 26, 2014 at 11:43 AM, Alejandro Varas G. <[email protected]> wrote: > Hi, > > You should use User.objects.get(id=X) > > Best > El 26/09/2014 15:28, "aRkadeFR" <[email protected]> escribió: > > > > > Hey! > > > > I'm having a hard time trying to reduce the number of SQL queries on a > view. > > > > Basically, I'm fetching all my User, with User.objects.all(), and save > this > > queryset as AllUser. > > > > Then every time I need to get the user with the id = X , I'm calling a > function > > 'get_user_from_id', that iterate over the AllUser queryset variable, and > when > > it finds the id, returns it. > > > > I considerably reduced the number of SQL queries, but I would like to > know if > > you think of a better way? > > > > Thank you > > > > -- > > You received this message because you are subscribed to the Google > Groups "Django users" group. > > To unsubscribe from this group and stop receiving emails from it, send > an email to [email protected]. > > To post to this group, send email to [email protected]. > > Visit this group at http://groups.google.com/group/django-users. > > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/20140926182939.GA26744%40rkade-thinkpad > . > > For more options, visit https://groups.google.com/d/optout. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/CAL60nj%2BBtqs9CXu8drOiWPoJ7aUkAKjLqXKCxmR_TMTeOOH%3DGw%40mail.gmail.com > <https://groups.google.com/d/msgid/django-users/CAL60nj%2BBtqs9CXu8drOiWPoJ7aUkAKjLqXKCxmR_TMTeOOH%3DGw%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > > For more options, visit https://groups.google.com/d/optout. > -- James Brewer jamesbrewer.io -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAKj8pVpqBgpFDQ0BruHXLWe2q1CRURMEejokhMKpD5bfs9hGGA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.

