Great library, I've been testing with PostgreSQL 9.6 and it's looking great! I quickly noticed that the default filtering is limited. It uses (SearchFilter,) by default.
I'd like like to suggest that we remove this and allow filtering to only be determined by DEFAULT_FILTER_BACKENDS, as that is already inherited from ModelViewSet.
If we set both variables, search_fields = filter_fields = searchable_field_names, then we can support SearchFilter and django_filters.rest_framework.DjangoFilterBackend interchangeably if configured in settings.py.
I also removed the usage of is_textual_field because it was filtering out models.DateTimeField and models.Integer, which I would also like to expose for query parameter filtering.
@staticmethod
def get_viewset(model_class, serializer_klass):
searchable_field_names = [
field.name for field in model_class._meta.get_fields()
]
class ViewSet(viewsets.ModelViewSet):
serializer_class = serializer_klass
queryset = model_class.objects.all()
search_fields = filter_fields = searchable_field_names
return type("{}ViewSet".format(model_class._meta), (ViewSet,), {})
Great library, I've been testing with PostgreSQL 9.6 and it's looking great! I quickly noticed that the default filtering is limited. It uses
(SearchFilter,)
by default.I'd like like to suggest that we remove this and allow filtering to only be determined by
DEFAULT_FILTER_BACKENDS
, as that is already inherited fromModelViewSet
.If we set both variables,
search_fields = filter_fields = searchable_field_names
, then we can supportSearchFilter
anddjango_filters.rest_framework.DjangoFilterBackend
interchangeably if configured insettings.py
.I also removed the usage of
is_textual_field
because it was filtering outmodels.DateTimeField
andmodels.Integer
, which I would also like to expose for query parameter filtering.Let me know your thoughts! :)