Как найти сумму наибольших 5 значений

изучаю джанго, может кто подскажет куда копать, как правильно сделать запрос...

С 1 по 4 пункты получилось, как сделать 5 пункт?

Вывести список Игроков

  1. Сумма очков
  2. Сумма очков за Тип турнира 1 , 2
  3. Кол-во очков
  4. Кол-во очков за Тип турнира 1 , 2
  5. Сумма Наибольших 5 Очков из тип турнира 1 (затем из 2)

models.py

    class Player(models.Model):
        name = models.CharField(max_length=150,)
    
    class TypeTour(models.Model):
        type = models.CharField(max_length=150, ) # из данных там только 2 строки
    
    class Tour(models.Model):
        name_tour = models.CharField(max_length=150,)
        type_tour = models.ForeignKey(TypeTour, default=1)
       
    class Score(models.Model):
        name_tour = models.ForeignKey(Tour,)
        name_player = models.ForeignKey(Player,)
        score = models.IntegerField()

views.py

class PlayersList(generic.ListView):
model = Player

def get_queryset(self):
    
    return Player.objects.filter(status=1).annotate(score_summ=Sum('score__score'))
    .annotate(score_summ_i=Sum('score__score', filter=Q(score__name_tour_id__type_tour_id=1)))
    .annotate(score_summ_r=Sum('score__score', filter=Q(score__name_tour_id__type_tour_id=2)))
    .annotate(score_count=Count('score', filter=Q(score__status=1)))
    .annotate(score_count_i=Count('score', filter=Q(score__name_tour_id__type_tour_id=1)))
    .annotate(score_count_r=Count('score', filter=Q(score__name_tour_id__type_tour_id=2)))
Вернуться на верх