mirror of https://github.com/snachodog/mybuddy.git
change api date filter to datetime filter
This commit is contained in:
parent
9d916e19f1
commit
611fb85314
|
@ -1,7 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from django_filters import rest_framework as filters
|
|
||||||
|
|
||||||
from core import models
|
from core import models
|
||||||
|
from django_filters import rest_framework as filters
|
||||||
|
|
||||||
|
|
||||||
class CharInFilter(filters.BaseInFilter, filters.CharFilter):
|
class CharInFilter(filters.BaseInFilter, filters.CharFilter):
|
||||||
|
@ -26,12 +25,12 @@ class TagsFieldFilter(filters.FilterSet):
|
||||||
|
|
||||||
|
|
||||||
class TimeFieldFilter(ChildFieldFilter):
|
class TimeFieldFilter(ChildFieldFilter):
|
||||||
date = filters.DateFilter(field_name="time__date", label="Date")
|
date = filters.IsoDateTimeFilter(field_name="time", label="DateTime")
|
||||||
date_max = filters.DateFilter(
|
date_max = filters.IsoDateTimeFilter(
|
||||||
field_name="time__date", label="Max. Date", lookup_expr="lte"
|
field_name="time", label="Max. DateTime", lookup_expr="lte"
|
||||||
)
|
)
|
||||||
date_min = filters.DateFilter(
|
date_min = filters.IsoDateTimeFilter(
|
||||||
field_name="time__date", label="Min. Date", lookup_expr="gte"
|
field_name="time", label="Min. DateTime", lookup_expr="gte"
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -40,19 +39,19 @@ class TimeFieldFilter(ChildFieldFilter):
|
||||||
|
|
||||||
|
|
||||||
class StartEndFieldFilter(ChildFieldFilter):
|
class StartEndFieldFilter(ChildFieldFilter):
|
||||||
end = filters.DateFilter(field_name="end__date", label="End Date")
|
end = filters.IsoDateTimeFilter(field_name="end", label="End DateTime")
|
||||||
end_max = filters.DateFilter(
|
end_max = filters.IsoDateTimeFilter(
|
||||||
field_name="end__date", label="Max. End Date", lookup_expr="lte"
|
field_name="end", label="Max. End DateTime", lookup_expr="lte"
|
||||||
)
|
)
|
||||||
end_min = filters.DateFilter(
|
end_min = filters.IsoDateTimeFilter(
|
||||||
field_name="end__date", label="Min. End Date", lookup_expr="gte"
|
field_name="end", label="Min. End DateTime", lookup_expr="gte"
|
||||||
)
|
)
|
||||||
start = filters.DateFilter(field_name="start__date", label="Start Date")
|
start = filters.IsoDateTimeFilter(field_name="start", label="Start DateTime")
|
||||||
start_max = filters.DateFilter(
|
start_max = filters.IsoDateTimeFilter(
|
||||||
field_name="start__date", lookup_expr="lte", label="Max. End Date"
|
field_name="start", lookup_expr="lte", label="Max. End DateTime"
|
||||||
)
|
)
|
||||||
start_min = filters.DateFilter(
|
start_min = filters.IsoDateTimeFilter(
|
||||||
field_name="start__date", lookup_expr="gte", label="Min. Start Date"
|
field_name="start", lookup_expr="gte", label="Min. Start DateTime"
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
23
api/tests.py
23
api/tests.py
|
@ -1,12 +1,10 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from django.urls import reverse
|
|
||||||
from django.utils import timezone
|
|
||||||
|
|
||||||
from rest_framework import status
|
|
||||||
from rest_framework.test import APITestCase
|
|
||||||
|
|
||||||
from babybuddy.models import User
|
from babybuddy.models import User
|
||||||
from core import models
|
from core import models
|
||||||
|
from django.urls import reverse
|
||||||
|
from django.utils import timezone
|
||||||
|
from rest_framework import status
|
||||||
|
from rest_framework.test import APITestCase
|
||||||
|
|
||||||
|
|
||||||
class TestBase:
|
class TestBase:
|
||||||
|
@ -258,6 +256,19 @@ class FeedingAPITestCase(TestBase.BabyBuddyAPITestCaseBase):
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# check backwards compatibility
|
||||||
|
def test_get_with_date_filter(self):
|
||||||
|
response = self.client.get(self.endpoint, {"start_min": "2017-11-18"})
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
self.assertEqual(response.data["count"], 3)
|
||||||
|
|
||||||
|
def test_get_with_iso_filter(self):
|
||||||
|
response = self.client.get(
|
||||||
|
self.endpoint, {"start_min": "2017-11-18T11:30:00-05:00"}
|
||||||
|
)
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
self.assertEqual(response.data["count"], 2)
|
||||||
|
|
||||||
def test_post(self):
|
def test_post(self):
|
||||||
data = {
|
data = {
|
||||||
"child": 1,
|
"child": 1,
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue