is there any way in which we can pass all the fields of a model to django filter backend
without explicitly passing the names of fields in search_fields and filter_fields
i have made a generic viewset which serializes all the fields of the model passed to it, but i am facing problem in applying generic filters to it
for eg,
class UserListView(generics.ListAPIView):
queryset = User.objects.all()
serializer_class = UserSerializer
filter_backends = (filters.SearchFilter,)
search_fields = ('username', 'email')
in the above code, we have explicitly passed search_fields
but in my code, i can't pass the fields explicitely as everytime different model may be passed.
I dont think it's wise to do it, as some fields can reveal sensitive information, but you can try to pass all fields from the model:
Here are the docs for using
get_fields
: