drf-forms / drf-schema-adapter

Making using Django with frontend libraries and frameworks DRYer
http://drf-schema-adapter.readthedocs.io/en/latest/
MIT License
157 stars 40 forks source link

filter_class does not respect filter_fields, Filter.fields #41

Closed gthieleb closed 6 years ago

gthieleb commented 6 years ago

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.

gthieleb commented 6 years ago

endpointfiltering-2018-05-12

gthieleb commented 6 years ago

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

nanuxbe commented 6 years ago

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.

nanuxbe commented 6 years ago

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

nanuxbe commented 6 years ago

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

nanuxbe commented 6 years ago

Solved by https://github.com/drf-forms/drf-schema-adapter/commit/8a121cfc3698e43b9c71156b392484aa49ba2468