The basic way to filter is by overwriting the get_queryset method of Generic Views.
> Note that Viewsets also have the generic view.
Take a look at this example:
classPurchaseList(generics.ListAPIView):serializer_class=PurchaseSerializerdefget_queryset(self):"""
Request obj.: self.request
How to get that parameters of get request.
1. username = self.kwargs['username']
2. username = self.request.query_params.get('username', None)
"""username=self.request.query_params.get('username',None)returnPurchase.objects.filter(purchaser__username=username)
Search Filter Class
Location: form rest_framework.filters import SearchFilter
Top comments (1)
I'm glad to read a post about DRF, everything seems to be related to javascript these days.