carltongibson / django-filter

A generic system for filtering Django QuerySets based on user selections
https://django-filter.readthedocs.io/en/main/
Other
4.39k stars 760 forks source link

Filter by list of IDs #1664

Open stefan6419846 opened 1 month ago

stefan6419846 commented 1 month ago

I am currently trying to filter a by list of IDs, but it seems like this is limited to two values.

Let's say I have the following code:

class NumberInFilter(BaseInFilter, NumberFilter):
    pass

class MyModelFilter(FilterSet):
    pk__in = NumberInFilter(field_name='id', lookup_expr='in')

    class Meta:
        model = MyModel
        fields = {
            'name': ['exact', 'contains'],
        }

This will be rendered as:

<input type="number" name="pk__in" step="any" class="form-control is-valid" placeholder="ID ist in" id="id_pk__in">

Additionally, I get the query parameter pk__in=.

Unfortunately, this does not behave in clean manner:

The current state is not consistent and especially the default number-only input field does not really feel right. Did I miss something for the UI or is this just a limitation of the library?