class PositionListView(generics.ListAPIView): serializer_class = PositionListSerializer filter_backends = (DjangoFilterBackend,) filter_fields = ('type', 'experience', 'city',) def get_queryset(self): """ Optionally restricts the returned purchases to a given user, by filtering against a `username` query parameter in the URL. """ queryset = Position.objects.filter(is_public=True) type_id = self.request.query_params.get('type', None) if type_id is not None: queryset = queryset.filter(type__id=type_id) exp_id = self.request.query_params.get('experience', None) if exp_id is not None: queryset = queryset.filter(experience__id=exp_id) city_id = self.request.query_params.get('city', None) if city_id is not None: queryset = queryset.filter(city__id=city_id) return queryset.order_by('-create_date')
根据 type experience city 来对职位列表进行搜索