class OwnerList(generics.ListAPIView):
serializer_class = OwnerDetailSerializer
# queryset = Person.objects.filter(customuser__userrole__role__name='OWNER').distinct()
permission_classes = [IsAuthenticated]
filter_backends = [DjangoFilterBackend]
def get_queryset(self):
return super(OwnerList, self).get_queryset()
I have this simple view and i am trying to over ride the get_queryset. The issue is that when this view is used i get :
return super(OwnerList, self).get_queryset()
File "C:\Users\kdalipaj\PycharmProjects\LTC SYSTEM\venv\lib\site-packages\rest_framework\generics.py", line 63, in get_queryset assert self.queryset is not None, (
AssertionError: 'OwnerList' should either include a
queryset
attribute, or override theget_queryset()
method.
Why is this happening?
Your code is:
it means: "Call method get_queryset of ListAPIView.
ListAPIView doesn't have get_queryset method itself but GenericAPIView (which is a parent of ListAPIView) has one.
And get_queryset of the GenericAPIView doing simple thing: it throwing assertion.
So, you shouldn't call
Just create your own queryset and return it from the function. For example:
Another solution is to set
queryset
variable at a class-level: