File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33from django .db .transaction import atomic
44
5+ from django .db .models import Prefetch
56from django .shortcuts import get_object_or_404
67from django .db .utils import IntegrityError
78from rest_framework import mixins , status , viewsets
@@ -53,9 +54,12 @@ def get_serializer_class(self):
5354
5455 @action (detail = False , methods = ["GET" ], url_path = "with-sponsor" )
5556 def list_with_levels (self , request , version ):
56- serializer = self .get_serializer (
57- self .get_queryset ().filter (sponsor__paid_at__isnull = False ), many = True
57+ queryset = self .get_queryset ().prefetch_related (
58+ Prefetch (
59+ "sponsor_set" , queryset = Sponsor .objects .filter (paid_at__isnull = False )
60+ )
5861 )
62+ serializer = self .get_serializer (queryset , many = True )
5963 return Response (serializer .data )
6064
6165 @action (detail = False , methods = ["POST" ])
You can’t perform that action at this time.
0 commit comments