有没有办法用Django获得类似Excel的过滤?

时间:2019-05-28 11:47:23

标签: django django-filter

我想为我的Django提供简单的过滤器

我尝试了FilterSets,但是没有得到预期的结果

    31 class AnnonceFilter(django_filters.rest_framework.FilterSet):
    32     class Meta:
    33         model = Annonce
 S> 34         fields = ['advert_type', 'asset_type', 'sales_type', 'price', 'area', 'department', 'department_id', 'city', 'postal_code']


    52 class AnnonceMergedList(generics.ListAPIView):
    53     authentication_classes = ()
    54     permission_classes = ()
    55     serializer_class = AnnonceMergedListSerializer
    56     pagination_class = LargeResultsSetPagination
    57     filter_backends = (DjangoFilterBackend,)
    58     filter_class = AnnonceFilter
 S> 59     filterset_fields = ('advert_type', 'asset_type', 'sales_type', 'price', 'area', 'department', 'department_id', 'city', 'postal_code')
 S> 60     #search_fields = ('advert_type', 'asset_type', 'sales_type', 'price', 'area', 'department', 'department_id', 'city', 'postal_code', 'description')
    61     # queryset = Annonce.objects.all()
    62 
    63     def get_queryset(self):
    64         # Make the querysets for each database
 S> 65         q1 = Annonce.objects.using('leboncoin').annotate(website_name=Value('website1', output_field=CharField())).all()
 S> 66         q2 = Annonce.objects.using('pap').annotate(website_name=Value('website2', output_field=CharField())).all()
    67         return q1 | q2

我想为每个字段定义一个可能的选择列表,也许这些选择将由另一条路线返回。 我不知道该怎么做。

0 个答案:

没有答案