Filtering

2020-12-11  本文已影响0人  xncode

尽管可通过get queryset来过滤,但可利用

可设置项目通用filter

REST_FRAMEWORK = {
    'DEFAULT_FILTER_BACKENDS': ('django_filters.rest_framework.DjangoFilterBackend',)
}

也可在view中指定了filter_backends

class JobListAPIView(ListAPIView):

    serializer_class = JobSerializer
    queryset = WorkopolisJob.objects.all()
    filter_backends = [django_filters.rest_framework.DjangoFilterBackend]
    filter_fields = ('industry', 'type', 'location')
上一篇下一篇

猜你喜欢

热点阅读