drf-forms/drf-schema-adapter

filter_class does not respect filter_fields, Filter.fields

Closed this issue · 6 comments

endpoints.py:

@register
class StageEndpoint(Endpoint):

    model = Stage
    read_only = True

    filter_class = StageFilter
    filter_fields = ('middleware', 'tshirt_size', 'service_level')

filtersets.py:

class MiddlewareSpecFilter(FilterSet):
    """ this is the base filter
        based on the intermediate table middlewarespec
        to filter specific attributes that are related to middlewarespecification """
    middleware = filters.CharFilter(label='Middleware',
            name='middlewarespecification__middleware__name',
            distinct=True)
    stage = filters.CharFilter(label='Stage',
            name='middlewarespecification__stage__stage',
            distinct=True)
    service_level = filters.CharFilter(label='Service Level',
            name='middlewarespecification__service_level',
            distinct=True)
    tshirt_size = filters.CharFilter(label='Tshirt Size',
            name='middlewarespecification__tshirt_size',
            distinct=True)

class StageFilter(MiddlewareSpecFilter):

    class Meta:
        model = Stage
        fields = ('middleware',
                  'tshirt_size',
                  'service_level')

The expected behavior is that filtering is possible for middleware, tshirt_size, service_level.
The result is that filtering is also available for stage.

Screenshot appended.

Same behavior with traditional viewset / filterset.
I opened issue carltongibson/django-filter#905

Yes, this is not an issue with drf-schema-adapter, as you've noted, this is an issue with django-filter and it might even be an intended feature.

I'm closing this issue since it's not related to this library

Even if this is an upstream issue, there might be something drf-schema-adapter can do about it. Re-opening the issue

Solved by 8a121cf