Hi, I would do something like this:
top_videos = {} for i in xrange(1,6): videos = Video.objects.filter(category=i).order_by('-hit_count') if videos: top_videos[i] = videos[0] Then, access the top videos via the top_videos dict. Cheers, Gabriel -- Gabriel de Carvalho Nogueira Reis Software Developer +44 7907 823942 On Wed, Jan 27, 2010 at 3:45 PM, grimmus <graham.col...@gmail.com> wrote: > Hi, > > On the homepage of my site i display 1 main video and then the most > popular video from each of the 5 categories, which is determined by a > hit count. > > Basically i need something like the following > > tv_video = Video.objects.filter(category=1).order_by('-hit_count') > > But i need an object returned that gets the most popular video (just > the first one) from each category (1-5) > > Does someone have an idea of the most efficient way to achieve this ? > > Thanks, hope i was clear. > > -- > 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<django-users%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > > -- 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.