-
Notifications
You must be signed in to change notification settings - Fork 755
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
IN lookup #394
Comments
Hi @maxtepkeev. Yes - this is the expected behavior. Filters are not 'expression aware' and will not alter behavior according to their You can either manually create the filter class as you've done in the second example, or you can automatically generate filters with the dictionary style syntax for eg, class MyModelFilter(Filters.FilterSet):
class Meta:
model = MyModel
fields = {
'my_field': ['exact', 'in', ...],
} |
Hi @rpkilby Thanks for reply. IMHO that is not very obvious from the documentation, so maybe you can add some more information about that in the docs. Also, the second example with |
@maxtepkeev Any PRs on the docs are very welcome! I think the underlying issue is the CharFilter is only expecting (receiving?) a single value, not a list; that comes from how the widget maps data from the |
@carltongibson I'll try to work on this later tonight. Could rework this into a section on common problems and/or theory. @maxtepkeev Here are the docs on mixing the |
@rpkilby Yes, it was hard to find, but I've read this section and after that I implemented my current working solution, i.e.: from django_filters import filters as df_filters
from rest_framework import filters
from ..models import MyModel
class CharInFilter(df_filters.BaseInFilter, df_filters.CharFilter):
pass
class MyModelFilter(filters.FilterSet):
my_field = CharInFilter()
class Meta:
model = MyModel
from rest_framework import filters
from ..models import MyModel
class MyModelFilter(filters.FilterSet):
class Meta:
model = MyModel
fields = {
'my_field': ['in'],
} As I said earlier, I'm using django-filter with django-rest-framework, I'm using |
Ah, you should be filtering with class ProductFilter(filterset.Filter):
class Meta:
model = Product
fields = {'price': ['exact', 'in', 'lt', 'gt'], } Would generate |
Of course, my bad, it works now. But if I don't like the |
Yep, and that's fine if you only have the one filter for that field. If you have multiple filters for a field though, you'll need to use some naming strategy to differentiate between them. eg, |
Yes, that makes sense. Thanks. I have no more questions. |
Hi,
I'm using django-filter with django-rest-framework, this one doesn't work, it just returns nothing:
But this one does and works as expected:
Is this a normal and expected behaviour or am I doing something wrong here ? Thanks.
The text was updated successfully, but these errors were encountered: