I'va a django-rest-framework viewset like this:
class MyFilterSet(django_filters.FilterSet):
class Meta:
model = MyModel
fields = {
'code': ['exact', 'icontains', 'istartswith'],
'name': ['exact', 'icontains', 'istartswith'],
'status': ['exact'],
...
}
class MyViewSet(viewsets.ModelViewSet):
serializer_class = MySerializer
model = MyModel
filter_backends = (filters.OrderingFilter, filters.SearchFilter, filters.DjangoFilterBackend)
# for DjangoFilterBackend
filter_class = MyFilterSet
# for SearchFilter
search_fields = (
'code',
'name',
'description',
...
)
# for OrderingFilter
ordering_fields = ('code', 'name', 'status', ...)
How can I inspect this API to get allowed filters (needed by my frontend page)?
Aucun commentaire:
Enregistrer un commentaire