-
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
rest_framework.DateFilter(lookup_expr='lte') is not working as expected (doesn't get date exclusively despite 'lte' ) #1161
Comments
This is not a bug. Change your DateRangeFilter filter to the following so it works like you would expect:
Notice the The reason after this is that you need to extract the |
@dalvtor is correct that you should use the class DateRangeFilter(FilterSet):
date_from = DateFilter(field_name='submitted_at', lookup_expr='date__gte')
|
Just got bit by the same issue. The workaround @rpkilby suggests does indeed work but it's not intuitive, if you use a DateFilter you certainly would expect the lte comparison is against the date. Maybe we could at least add this to the documentation of DateFilter if we can't fix it in a good way? |
Just to contribute, I had the same problems with DateFilter and DateFromToRangeFilter today. Turns out I was passing nonexistent dates (For example, sending the day part of the date as 31st when the month only had 30 days). After making sure the day part was according to each month, worked like a breeze. |
Using
django-filter==2.2.0
djangorestframework==3.10.3
Windows 10
DB: PostgreSQL 11.6
I wanted to filter by date on my submitted_at DateTime field so I made this
It works fine for date_from as expected but for date_to it doesn't return the date exclusively as it supposes to do
for example:
https://<base_url>?date_from=2019-01-04&date_to=2019-01-05
expected data
https://<base_url>?date_from=2019-01-04&date_to=2019-01-05
actual data:
and that's a bit odd, as if something is wrong it should not work at all not only for date_to unless there is some reason
I know I'm giving it only dates but no warning was in the console and everything was just ok
The text was updated successfully, but these errors were encountered: