[Answered ]-Filtering using URL with DRF

2๐Ÿ‘

โœ…

I used django-filter, and the URL filter instead. Minimal code was required. I recommend this over django-filters.

I would also like to be able to combine levels (eg write api/level/1&2&3) but if no one answers I understand it is outside the scope of my original question.

filters.py

from rest_framework import filters, generics
from .serializers import TagSerializer
from Tril.models import Tag

class TagLevel(generics.ListAPIView):
    serializer_class = TagSerializer

    def get_queryset(self):
        taglevel = self.kwargs['level']
        return Tag.objects.filter(level=level)

urls.py

url('^level/(?P<level>.+)/$', Level.as_view()

๐Ÿ‘คYcon

Leave a comment