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

How to use the field 'in' in django-rest-framework-filters, like 'user_id__in=[12,13]'? #360

Open
weiyong996 opened this issue Aug 13, 2023 · 2 comments

Comments

@weiyong996
Copy link

My FilterSet

class UserFilter(filters.FilterSet):
    class Meta:
        model = User
        fields = {'id': ['exact', 'in',]}

Evn

python 3.7
django 2.1.1
django-filter 2.1.0
djangorestframework 3.8.2
djangorestframework-filters 1.0.0.dev2

Issue Description

I use postman send a request

I want to match to ids (for example: Bob, Alice), the logic url is: /api/companies?user_id__in=[12,13]
(I know that both '[' and ']' will be converted to %5B and %5D by browser, so true url is: /api/companies?user_id__in=%5BBob,Alice%5D)

I hope get two records by user_id__in[12,13], unfortunately I get all records, so how to resolve the problem?
Is there something wrong with me?

@truongvan
Copy link

Use with QueryArrayWidget
It supports those strings:

1. Values can be provided as csv string:  ?foo=bar,baz
2. Values can be provided as query array: ?foo[]=bar&foo[]=baz
3. Values can be provided as query array: ?foo=bar&foo=baz

@Greg-Hamel
Copy link

@weiyong996 For your implementation, using /api/companies?user_id__in=12,13 should give you the results you are looking for.
Ensure the UserFilter is defined in the view associated to the /companies url

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

3 participants