Tech
Tech

Reputation: 935

Can I change datetime-local format for django-filters?

I'm using django-filters for a datetime filter.

When I try to use datetime-local my form sends the date time query like this:

2020-07-07T18:39

But my django-filter accept the format just like this:

2020-07-07 18:39

And here is my django function for django-filter:

def paketdok(request):
    siparis_list = Siparisler.objects.filter(paketlenme_tarihi__isnull=False)
    siparis_filter = PaketFilter(request.GET, queryset=siparis_list)
    return render(request, 'paketlenmis_arama.html', {'filter': siparis_filter})

My PaketFilter:

paketlenme_tarihi = django_filters.DateTimeFromToRangeFilter(widget=django_filters.widgets.RangeWidget(attrs={'type':'datetime-local'}))

Can I change the format of datetime-local input field somehow?

Upvotes: 2

Views: 619

Answers (1)

AKX
AKX

Reputation: 168967

You can't change what datetime-local does - for sanity's sake, it will always output an ISO8601 datetime.

Happily, though, django-filter ships with IsoDateTimeFilter / IsoDateTimeField, which accept ISO8601 datetimes.

You should be able to just switch to that filter or field.

Upvotes: 4

Related Questions