可能的组合咨询过滤器'filter?name__icontains = pr&enabled = true'

时间:2019-04-20 16:59:44

标签: django python-3.x django-rest-framework django-filter

Estoy haciendo una filtro para StockType (股票类型)是由nombre或sean activos或inactivos pero no conosigo ese resultado

不要在任何人身上碰到麻烦了激活灭活,请给我一个名字名称

>

AlgúnConsejo para este tipo de filtrado?我seria de mucha ayuda!

class StockTypetFilter(django_filters.FilterSet):

    class Meta:
        model = StockType
        fields = {
             #isnull, icontains, iexact
             'name': ['icontains'],
             'enabled': ['exact']
        }

class FilterView(generics.ListAPIView):
    queryset = StockType.objects.order_by('-id').all()
    serializer_class = StockTypeSerializers
    filter_class = StockTypetFilter
    pagination_class = StandardResultsSetPagination
    permission_classes = [permissions.IsAuthenticated, permissions.IsAdminUser]


#En la url tengo de esta manera
re_path(r'^stock-types/filter?$', FilterView.as_view(), name='stocks-types-filter'),
Al probar la api desde el postman
api/stock-types/filter?name__icontains=pr&enabled__icontains=true


{
    "count": 2,
    "next": null,
    "previous": null,
    "results": [
        {
            "id": 3,
            "created_by": "meli",
            "updated_by": "meli",
            "create_date": "2019-04-14T15:35:44.246486",
            "update_date": "2019-04-14T17:26:55.018930",
            "enabled": true,
            "name": "PRUEBA TEST"
        },
        {
            "id": 2,
            "created_by": "meli",
            "updated_by": "meli",
            "create_date": "2019-04-14T15:15:18.956902",
            "update_date": "2019-04-14T16:05:04.047478",
            "enabled": false,
            "name": "COMPRAS"
        }
    ]
}

0 个答案:

没有答案