1👍
✅
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.
0👍
‘objs=Modelname.objects.filter(student__in=malerep).order_by(‘-Votes’,’-student__Percentage’)’
then using objs[0]
i was able to access the object of the student with max votes and max percentage in case of a tie.
- [Answer]-Django: Cannot create bounded form with ImageField
- [Answer]-Localhost for django not loading after creating table in sqlite
- [Answer]-Python-social-auth logs into 3rd party service (like facebook) along with logging into my app
- [Answer]-Django return to index when there is no next= in URL
- [Answer]-South not working in Webfaction
Source:stackexchange.com