django rest framework filter

后端 未结 3 1403
名媛妹妹
名媛妹妹 2020-12-29 23:41

I\'m working with API made from Django rest framework, I am trying to make a filter to a JSON This is my serializers.py file

from rest_framewo         


        
3条回答
  •  感情败类
    2020-12-30 00:09

    You need to define filter backend and all related fields you're planning to filter on:

    class EstablecimientoViewSet(viewsets.ModelViewSet):
        filter_backends = (filters.DjangoFilterBackend,)
        filter_fields = ('categoria', 'categoria__titulo',)
    

    example:

    URL?categoria__titulo=Categoria 1
    

提交回复
热议问题