I have the relationship follow as:
class Question(models.Model):
content = models.CharField(max_length=128)
class Answer(models.Model):
content = models.CharField(max_length=128)
question = models.ForeignKey(Question)
num_vote = models.IntegerField()
I want to retrieve the answers, which have the max voting. I tried this statement but it isn’t correctly.
answers = Answer.objects.filter(question__exact=1).annotate(Max('num_vote'))
Some predefined number of answers? You you need e.g. 5 high-scored answers use
If you need all the answers with max
num_voteyou need 2 queries.