django, get an object from a list of filtered objects which has the maximum value for a field
At this point, you have two choice:
First, use "max" to get the max value of certain field and use that max value to retrieve the particular student instance.
Good side, this is easy to implement; bad side, you need to hit database twice to achieve your goal.
Second, use raw(). You can perform all the complicate query you want. And that will solve your problem.
Good side, you have the maximal freedom to preform any query; bad side, require sql knowledges.
Modelname.objects.filter(student__in=malerep).order_by('-Votes','-student__Percentage')
Here i want to specifically get the student who has the maximum number of votes.
What i am trying to do is, to get the list of students who stood for an election and got some votes and then sort them based on the number of votes they got. Now if i can access the first object in this list , i can make necessary modifications for the student in the database who won the election and also get the details of the rest.
I am stuck at this point. Please help
Thanx in advance.