-
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
datetime filter don't support datetime input formats from project settings file #668
Comments
Hi @KushGoyal - which filterset class are you using? |
@rpkilby I am using |
@KushGoyal - That's odd - it's the only obvious answer that comes to mind. If you look at this line here, you'll see that the DRF filterset specifically uses the Could you provide a more complete example of your filterset? An example test case would be even more helpful. |
The An alternative is to mix |
I don't want to be adding a whole |
@rpkilby @carltongibson Would you have an example of mixing I am also trying to make Here is my code so far: from django.db import models
from django_filters import rest_framework as filters
from .models import Event
class EventFilter (filters.FilterSet):
date__range = filters.DateTimeFromToRangeFilter(name='date')
class Meta:
model = Event
fields = {
'date': ['exact', 'lte', 'gte']
}
filter_overrides = {
models.DateTimeField: {
'filter_class': filters.IsoDateTimeFilter
},
} Thanks! |
Hi @lucas-bremond, the CSV filter bases are used as mixins. class IsoDateTimeRangeFilter(BaseRangeFilter, IsoDateTimeFilter):
pass
class EventFilter (filters.FilterSet):
date__range = IsoDateTimeRangeFilter(name='date') |
@rpkilby That is indeed working quite perfectly! Thank you! Just a quick question (the cherry on the cake): is there any easy way to have this new
In any case, thank you so much for your help. |
That would require custom html/js. The CSV range filter uses a single input and expects two values separated by a comma. The original If you want to use two inputs, but submit as a single CSV, then you'd need to write custom form html that presents the two inputs, then JS that intercepts the form submit, combines them as a single input, then submits the altered data. |
I am facing 2 issues:
when using django filter with django rest framework (DRF) datetime filters don't accept iso-8601 formats. DRF renders datetime objects as iso-8061. This creates confusion.
I added iso-8061 to django's datetime input formats setting. But django-filter still did not support it.
The text was updated successfully, but these errors were encountered: