title: How to add get_queryset function in apiview of Django rest framework?
body: <p>I am using Django APIView to include all my CRUD operation in a single api endpoint. But later on I had to use filtering logic based on the query parameters that have been passed. Hence I found it difficult to include it in a get api of APIView and made a separate api using generic view, ListAPiview.</p>
  <p>Here is the view:</p>
  <pre><code>class LeadsView(APIView):
      permission_classes = [IsAuthenticated]
  
      def get(self, request, pk=None, *args, **kwargs):
  
          id = pk
          if id is not None:
              abc = Lead.objects.get(id=id)
              serializer = LeadSerializer(abc)
              return serializer.data
  
      def post(self,request,*args,**kwargs):
          abc = LeadSerializer(data=request.data,many=True)
          if abc.is_valid():
              abc.save()
              return Response(abc.data, status=status.HTTP_201_CREATED)
          return Response(abc._errors, status=status.HTTP_400_BAD_REQUEST)
  
      def delete(self, request,pk, *args, **kwargs):
  </code></pre>
  <p>Now, I have to use filter class and also some custom filtering logic, I need to use get_queryset. Hence I have to create another api just for get method which I dont want.</p>
  <pre><code>class LeadAPIView(ListAPIView):
      authentication_classes = (TokenAuthentication,)
      permission_classes = (IsAuthenticated,)
      queryset = Lead.objects.all().order_by('-date_created')
      serializer_class = LeadSerializer
      filter_backends = [django_filters.rest_framework.DjangoFilterBackend]
      pagination_class = CustomPagination
      # filterset_fields = [ 'email','first_name','last_name','phone']
      filterset_class = LeadsFilter
  
      def get_queryset(self):
          source = self.request.GET.get(&quot;source&quot;, None)    #     
          lead_status = self.request.GET.get(&quot;lead_status&quot;, None)
          if source is not None:
              source_values = source.split(&quot;,&quot;)
              if lead_status is not None:
                  lead_status_values= lead_status.split(&quot;,&quot;)
                  return Lead.objects.filter(source__in=source_values,lead_status__in=lead_status_values)
              else:
                  return Lead.objects.filter(source__in=source_values)
          elif lead_status is not None:
              lead_status_values = lead_status.split(&quot;,&quot;)
              if source is not None:
                  source_values = source.split(&quot;,&quot;)
                  return Lead.objects.filter(lead_status__in=lead_status_values,source__in=source_values)
              else:
                  return Lead.objects.filter(lead_status__in=lead_status_values)
  
          return Lead.objects.all()
  </code></pre>
  <p>My question is, can I use get_queryset in the APIView instead of making another api?? Also, if I can use it, I assume I cant import <code>filterset_class = LeadsFilter</code> and also pagination? What will be the best approach??</p>
  <p>My urls:</p>
  <pre><code>path('leads', LeadAPIView.as_view(), name='leads'),
  path('lead', LeadsView.as_view(), name='leads-create'),
  path('lead/&lt;int:pk&gt;', LeadsView.as_view()),
  </code></pre>