miki725 / django-url-filter

Django URL Filter provides a safe way to filter data via human-friendly URLs.
http://django-url-filter.readthedocs.io/
Other
333 stars 77 forks source link

Using `__in` returns entire queryset #38

Closed kyleobrien91 closed 7 years ago

kyleobrien91 commented 7 years ago

Based on the documentation, it seems I should just be able to configure my viewset as follows and automatically get filtering. However, certain URL filtering seems to be ignored completed.

from django_filters.rest_framework import DjangoFilterBackend

class UsersViewSet(ModelViewSet):
    queryset = MyModel.objects.all()
    serializer_class = MyModelSerializer
    filter_backends = [DjangoFilterBackend]
    filter_fields = ['id']

Assuming that viewset maps to an endpoint like /users/, I should be able to use a query like /users?id__in=1,2,3,4,5 and only see results where the ID is either 1, 2, 3, 4 or 5.

However, that's not the case. Using that minimal setup, I can only use a filter like /users/?id=1. As soon as I use id__in=1,2,3,4,5, I get my entire queryset back - all 20 users.

Am I missing a setup step?

kyleobrien91 commented 7 years ago

I meant to include some information on my package versions

miki725 commented 7 years ago

from the code sample above it does not look like you are using django-url-filter:

from django_filters.rest_framework import DjangoFilterBackend

if you would like to use this package you can use:

from url_filter.integrations.drf import DjangoFilterBackend

and yes once you use that __in should be one of available lookups.

closing issue for now however feel free to reopen or create issues if you will have further issues.

kyleobrien91 commented 7 years ago

@miki725 - 100%. I was being an utter chop. It works perfectly.

miki725 commented 7 years ago

@kyleobrien91 np. everyone does those... 😄