Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter by list of IDs #1664

Open
stefan6419846 opened this issue Jun 4, 2024 · 0 comments
Open

Filter by list of IDs #1664

stefan6419846 opened this issue Jun 4, 2024 · 0 comments

Comments

@stefan6419846
Copy link

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:

  • In the UI, I can only enter up to two numbers due to the input field type, basically mapping to a floating point value (although getting the correct results). This is represented inside the URL as pk__in=1.2 for example.
  • Passing pk__in=1,2,6,10 in the URL explicitly seems to work as well and disables the regular input field behavior, now allowing to enter more than two numbers.

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant