Tôi có một mô hình với một DateTimeField:Filtering trên DateTimeField với Django Nghỉ ngơi Khung
class MyShell(models):
created = models.DateTimeField(auto_now=true)
Tôi đã một api liên kết với nó sử dụng Django Nghỉ ngơi Khung:
class ShellMessageFilter(django_filters.FilterSet):
created = django_filters.DateTimeFilter(name="created",lookup_type="gte")
class Meta:
model = ShellMessage
fields = ['created']
class ShellListViewSet(viewsets.ModelViewSet):
"""
List all ShellMessages
"""
serializer_class = ShellMessageSerializer
queryset = ShellMessage.objects.all()
filter_class = ShellMessageFilter
Khi tôi nhấn API của tôi sử dụng URL sau hoạt động hoàn hảo:
http://127.0.0.1:8000/api/shell/?created=2014-07-17
# It returns all shell with a date greater than the one provided in URL
Nhưng, tôi muốn làm nhiều hơn thế bằng cách lọc cơ sở dữ liệu e và một thời gian. Tôi đã thử các URL sau đây mà không thành công:
http://127.0.0.1:8000/api/shell/?created=2014-07-17T10:36:34.960Z
# It returns an empty array whereas there are items with a created field greater than 2014-07-17T10:36:34.960Z
Nếu các bạn biết làm thế nào để tiếp tục ... Tôi không tìm thấy bất kỳ thông tin tốt hay ví dụ trong tài liệu django-bộ lọc ...
Bạn có thể thử url này: http://127.0.0.1:8000/api/shell/?created=2014-07-17%2010:36:34.960? – AdelaN
Tôi nghĩ rằng tôi đang ở trong trường hợp này: https://github.com/tomchristie/django-rest-framework/issues/1338 –
Người đầu tiên cũng đề xuất xóa T khỏi URL, vì vậy, điều này cũng có thể hữu ích cho bạn . – AdelaN