0

to learn django I did a small app that let the user vote for the restaurant of their choice.
my table hold who voted for an option, and I am trying to query a table base on a date, and then get the one that most attribute is repeated. to know the restaurant that won.

and I would like to query base on a date(that way they can vote for some one different each day), and then get the restaurant_id that is most repeated.

Image of the table

table image link to image

https://www.dropbox.com/s/pszt46bdqstahky/table.png?dl=0

this is my code.

getting the queryset of dates. but from there how do I get the most repetead restaurant_id?

        the_max = Choice.objects.filter(date_vote=date)
        the_max = list(the_max)
        d = {x: the_max(x) for x in the_max}
        chosen_restaurant = max(d, key=d.get)

I was trying to put the repetition into a dictionary and the get the max from there. does django have another filter to do aggregation? with a little explanation how to use it?

thanks guys.

pelos
  • 1,744
  • 4
  • 24
  • 34
  • possible duplicate of [How to query as GROUP BY in django?](http://stackoverflow.com/questions/629551/how-to-query-as-group-by-in-django) –  Oct 21 '14 at 05:22
  • The [Aggregation](https://docs.djangoproject.com/en/dev/topics/db/aggregation/) docs should be pretty helpful for resolving this. – jvc26 Oct 21 '14 at 08:29
  • thanks, I don't know how to use the aggregations, I know how to use the average, or max, but max just give me the biggest number. – pelos Oct 22 '14 at 03:06

0 Answers0