How to make query of each parent only three 0r four child objects get in Django?

I have a list of videos which are belong from some of channels. I want to get only three videos per channel and pass as return value. My code is slice the list of videos not for all channel it's get only three objects. But i want to get each channel of three videos.

I don't understand how can i do that...

def each_channel_three_videos(request):

    videos = video.YTVideo.objects.select_related('channel')\
        .filter(channel__category__slug='vlogs')\
        .order_by('-per_sec_views')[:3]

    context = {
        'videos': videos,
    }
    return render(request, 'videos.html', context)

see this (https://docs.djangoproject.com/en/4.1/topics/pagination/) and see this (https://medium.com/dreidev/nested-pagination-md-6414a85b5501). have a goodday.

Back to Top