1👍
✅
The first and only parameter of get_queryset
is self
, not request
. You can access the request object with self.ruquest
, so:
class MySchoolsView(generics.ListAPIView):
permission_classes = [IsSchoolOwner, ]
serializer_class = SchoolSerializerList
def get_queryset(self):
return School.objects.filter(owner=self.request.user)
Your get_queryset
can also not return a Response
. You can raise a Http404
error:
from django.http import Http404
class MySchoolsView(generics.ListAPIView):
permission_classes = [IsSchoolOwner, ]
serializer_class = SchoolSerializerList
def get_queryset(self):
qs = School.objects.filter(owner=self.request.user)
if not qs:
raise Http404('No schools found')
return qs
Source:stackexchange.com