You need to look at SQL aggregates. See here - http://docs.djangoproject.com/en/dev/topics/db/aggregation/
On 25 August 2010 14:44, Joel Klabo <joelkl...@gmail.com> wrote: > I am trying to find a way to get a list of users ranked by the most > "drinks". The drink model has a User field so I am doing this to get > the info, based on the Drink model: > > http://dpaste.com/hold/233600/ > > But, this seems like craziness. Can't I just search the > User.objects.all().order_by('drinks') or something? Can i make a User > method? I'm confused, obviously. Try, User.objects.annotate(num_drinks=Count('drink')) (rough guess; I haven't really had a need to use this in my apps before :) > > Here is my Drink model so you have the whole picture: > > http://dpaste.com/hold/233601/ > > Any help on this would be great, I know there is something to be > learned from this.... > > -- > 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. > > -- 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.