Есть ли способ получить Excel-подобную фильтрацию с помощью Django? - PullRequest
0 голосов
/ 28 мая 2019

У меня есть простые фильтры для моего 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

Я хотел бы иметь определенный списоквозможный выбор для каждого поля, возможно, этот выбор будет возвращен другим маршрутом.Я понятия не имею, как это сделать.

...