|
|
@ -1,4 +1,4 @@ |
|
|
from django.db.models import Q |
|
|
|
|
|
|
|
|
from django.db.models import Q, Prefetch |
|
|
from rest_framework import generics, status |
|
|
from rest_framework import generics, status |
|
|
from rest_framework.authentication import TokenAuthentication |
|
|
from rest_framework.authentication import TokenAuthentication |
|
|
from rest_framework.decorators import action |
|
|
from rest_framework.decorators import action |
|
|
@ -45,10 +45,13 @@ class VideoCategoryListAPIView(generics.ListAPIView): |
|
|
|
|
|
|
|
|
def get_queryset(self): |
|
|
def get_queryset(self): |
|
|
""" |
|
|
""" |
|
|
Optimized queryset with prefetch_related for playlists |
|
|
|
|
|
|
|
|
Optimized queryset with prefetch_related for playlists with items |
|
|
""" |
|
|
""" |
|
|
return VideoCategory.objects.filter(status=True).prefetch_related( |
|
|
return VideoCategory.objects.filter(status=True).prefetch_related( |
|
|
'playlists' |
|
|
|
|
|
|
|
|
Prefetch( |
|
|
|
|
|
'playlists', |
|
|
|
|
|
queryset=VideoPlaylist.objects.filter(status=True, playlist_items__isnull=False).distinct() |
|
|
|
|
|
) |
|
|
).order_by('order') |
|
|
).order_by('order') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -85,7 +88,8 @@ class PinnedVideoCollectionListView(generics.ListAPIView): |
|
|
queryset = PinnedVideoCollection.objects.filter( |
|
|
queryset = PinnedVideoCollection.objects.filter( |
|
|
status=True, |
|
|
status=True, |
|
|
display_position=VideoCollection.DisplayPosition.PINNED, |
|
|
display_position=VideoCollection.DisplayPosition.PINNED, |
|
|
related_playlists__status=True |
|
|
|
|
|
|
|
|
related_playlists__status=True, |
|
|
|
|
|
related_playlists__playlist_items__isnull=False |
|
|
).distinct().order_by('order', '-created_at') |
|
|
).distinct().order_by('order', '-created_at') |
|
|
|
|
|
|
|
|
# Filter by bookmarks if requested |
|
|
# Filter by bookmarks if requested |
|
|
@ -155,8 +159,10 @@ class MiddleVideoCollectionListView(generics.ListAPIView): |
|
|
def get_queryset(self): |
|
|
def get_queryset(self): |
|
|
return VideoCollection.objects.filter( |
|
|
return VideoCollection.objects.filter( |
|
|
status=True, |
|
|
status=True, |
|
|
display_position=VideoCollection.DisplayPosition.MIDDLE |
|
|
|
|
|
).order_by('order', '-created_at') |
|
|
|
|
|
|
|
|
display_position=VideoCollection.DisplayPosition.MIDDLE, |
|
|
|
|
|
related_playlists__status=True, |
|
|
|
|
|
related_playlists__playlist_items__isnull=False |
|
|
|
|
|
).distinct().order_by('order', '-created_at') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def list(self, request, *args, **kwargs): |
|
|
def list(self, request, *args, **kwargs): |
|
|
@ -235,7 +241,10 @@ class VideoPlaylistListAPIView(generics.ListAPIView): |
|
|
return super().get(request, *args, **kwargs) |
|
|
return super().get(request, *args, **kwargs) |
|
|
|
|
|
|
|
|
def get_queryset(self): |
|
|
def get_queryset(self): |
|
|
queryset = VideoPlaylist.objects.filter(status=True).order_by('order', '-created_at') |
|
|
|
|
|
|
|
|
queryset = VideoPlaylist.objects.filter( |
|
|
|
|
|
status=True, |
|
|
|
|
|
playlist_items__isnull=False |
|
|
|
|
|
).distinct().order_by('order', '-created_at') |
|
|
|
|
|
|
|
|
# Search by title if search parameter is provided |
|
|
# Search by title if search parameter is provided |
|
|
search_query = self.request.query_params.get('search', None) |
|
|
search_query = self.request.query_params.get('search', None) |
|
|
@ -344,7 +353,10 @@ class VideoListAPIView(generics.ListAPIView): |
|
|
return super().get(request, *args, **kwargs) |
|
|
return super().get(request, *args, **kwargs) |
|
|
|
|
|
|
|
|
def get_queryset(self): |
|
|
def get_queryset(self): |
|
|
queryset = VideoPlaylist.objects.filter(status=True).order_by('order', '-created_at') |
|
|
|
|
|
|
|
|
queryset = VideoPlaylist.objects.filter( |
|
|
|
|
|
status=True, |
|
|
|
|
|
playlist_items__isnull=False |
|
|
|
|
|
).distinct().order_by('order', '-created_at') |
|
|
|
|
|
|
|
|
# Search by title if search parameter is provided |
|
|
# Search by title if search parameter is provided |
|
|
search_query = self.request.query_params.get('search', None) |
|
|
search_query = self.request.query_params.get('search', None) |
|
|
@ -413,7 +425,7 @@ class VideoPlaylistDetailAPIView(generics.RetrieveAPIView): |
|
|
return super().get(request, *args, **kwargs) |
|
|
return super().get(request, *args, **kwargs) |
|
|
|
|
|
|
|
|
def get_queryset(self): |
|
|
def get_queryset(self): |
|
|
return VideoPlaylist.objects.filter(status=True) |
|
|
|
|
|
|
|
|
return VideoPlaylist.objects.filter(status=True, playlist_items__isnull=False).distinct() |
|
|
|
|
|
|
|
|
def retrieve(self, request, *args, **kwargs): |
|
|
def retrieve(self, request, *args, **kwargs): |
|
|
instance = self.get_object() |
|
|
instance = self.get_object() |
|
|
|