Filter Json Records In Django Rest Framework
I created a DRF API endpoint in order to be able to grab some data to my database and show it on my Django page using Jquery. My sample data looks like this: { 'item': 'Someite
Solution 1:
Have a look on DRF doc.
In your case, I'd suggest you install django_filters
, then in your view:
from django_filters.rest_framework import DjangoFilterBackend
clasststList(generics.ListCreateAPIView):
queryset = tst.objects.all()
serializer_class = tstSerializer
filter_backends = [DjangoFilterBackend]
filterset_fields = ('Status',)
Solution 2:
a few days ago i found and watched this video and i think it's useful for your question, (about model managers and querysets):
https://www.youtube.com/watch?v=rjUmA_pkGtw
Solution 3:
You can set the queryset by django filter
queryset = tst.objects.filter(Status="Taken") # make sure the "Taken" is always Capitalized.
Post a Comment for "Filter Json Records In Django Rest Framework"