4👍
✅
Your GenericView
or ModelViewSet
should have a queryset
attribute that defines what set it should work on.
You need to add the prefetch_related
/ select_related
there.
class UserList(generics.ListCreateAPIView):
queryset = User.objects.all().prefetch_related('groups')
serializer_class = UserSerializer
permission_classes = (IsAdminUser,)
Source:stackexchange.com