过滤django模型的所有字段

时间:2014-07-01 13:28:24

标签: python django django-models django-rest-framework

我使用Django Rest FrameworkDjango Filters来限制API调用的结果。是否可以对序列化程序中列出的所有模型字段进行过滤?

import django_filters
from rest_framework import generics

class ProjectFilter(django_filters.FilterSet):
    class Meta:
        model = Project
        fields = '__all__'

class ProjectList(generics.ListAPIView):
    model = Project
    serializer_class = ProjectSerializer
    filter_class = ProjectFilter

我知道fields = '__all__'不起作用,但我想知道是否有可以在这里使用的语法,或者是否可以使用不同类型的filter_class

1 个答案:

答案 0 :(得分:0)

不确定我是否完全理解这个问题,但在您看来,您可以使用 When allowCredentials is true, allowedOrigins cannot contain the special value "*" since that cannot be set on the "Access-Control-Allow-Origin" response header. To allow credentials to a set of origins, list them explicitly or consider using "allowedOriginPatterns" instead.] with root cause 这意味着您可以过滤模型中的所有字段,例如

filterset_fields = '__all__'