-
Notifications
You must be signed in to change notification settings - Fork 771
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 make django-filter lookup_expr work for JSONField via declarable fields #1149
Comments
Hi @udos. I haven't read your issue in full, but it looks like you're running into #1013, which is unrelated to Beyond that, there are several issues that discuss difficulties with JSON support. If you just want simple value filters, the current recommendation is to declare them. It's verbose, but simple. e.g., class SegmentFilter(drf_filters.FilterSet):
elevation = FloatFilter(field_name='data__properties__ele__max')
elevation__lt = FloatFilter(field_name='data__properties__ele__max', lookup_expr='lt')
elevation__gt = FloatFilter(field_name='data__properties__ele__max', lookup_expr='gt')
elevation__lte = FloatFilter(field_name='data__properties__ele__max', lookup_expr='lte')
elevation__gte = FloatFilter(field_name='data__properties__ele__max', lookup_expr='gte') For more info on difficulties supporting |
thanks @rpkilby. yes, exactly. it's due to #1013 (I did not spot this :| ). I thought of the workaround to explicitly declare the filters, but I thought I was doing something wrong with the auto generation via fields. I agree that they should not fail silently. maybe a "currently not supported" warning/error would be nice to have. |
No worries - it's a confusing bug, especially given the general confusion over
If it weren't for the bug in #1013, you should have gotten a warning indicated that the field/lookup isn't supported. |
according docs
you can configure django-filter to apply multiple lookup expressions (
lookup_expr
) to various fields. this is done via declarable fields as following:in my case for field "elevation" (JSONField) unfortunately the
lookup_expr
are not applied. it always returns the full result.the code for the filter:
which I use in the following viewset:
the serializer is this:
note: on field "id" the
lookup_expr
lt, lte, *gt and gte are working.any ideas why they are not applied on field "elevation"?
The text was updated successfully, but these errors were encountered: