carltongibson / django-filter

A generic system for filtering Django QuerySets based on user selections

Home Page:https://django-filter.readthedocs.io/en/main/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

django-filter BaseInFilter type customization

quertenmont opened this issue · comments

Hello,

I am using django-filter with a classical "CharInFilter" that is defined (as recommended) by

class CharInFilter(BaseInFilter, CharFilter):
    pass

The open api type that comes out of this is 'array[string]', but that's incorrect, as the input is actually comma separated values the right type should be 'string'.
I tried to customize this class in order to fix the issue via:

from drf_spectacular.contrib.django_filters import DjangoFilterExtension
class CharInFilterExtension(DjangoFilterExtension):
    target_class = CharInFilter
    priority = 1
    match_subclasses = True

    def map_serializer_field(self, auto_schema, direction):
        return build_basic_type(OpenApiTypes.STR)

but this doesn't seem to have any effect.
I would appreciate recommendation on how to customize this.

Thanks for helping,
Loic

Hi Loic. I think this is better reported on spectacular, as I can really advise.

OOps, my bad, I was willing to post on spectacular github :-/