Add Diaper Change "amount" field data to API

This commit is contained in:
Christopher C. Wells 2020-01-26 14:30:00 -08:00
parent 3a7c8c92fd
commit c51e755c0f
4 changed files with 39 additions and 19 deletions

View File

@ -36,7 +36,7 @@ class ChildSerializer(serializers.HyperlinkedModelSerializer):
class DiaperChangeSerializer(CoreModelSerializer): class DiaperChangeSerializer(CoreModelSerializer):
class Meta: class Meta:
model = models.DiaperChange model = models.DiaperChange
fields = ('id', 'child', 'time', 'wet', 'solid', 'color') fields = ('id', 'child', 'time', 'wet', 'solid', 'color', 'amount')
class FeedingSerializer(CoreModelSerializer): class FeedingSerializer(CoreModelSerializer):

View File

@ -61,7 +61,8 @@ class DiaperChangeAPITestCase(APITestCase):
'time': '2017-11-18T14:00:00-05:00', 'time': '2017-11-18T14:00:00-05:00',
'wet': True, 'wet': True,
'solid': False, 'solid': False,
'color': '' 'color': '',
'amount': 2.25
}) })
def test_options(self): def test_options(self):
@ -75,12 +76,16 @@ class DiaperChangeAPITestCase(APITestCase):
'time': '2017-11-18T12:00:00-05:00', 'time': '2017-11-18T12:00:00-05:00',
'wet': True, 'wet': True,
'solid': True, 'solid': True,
'color': 'brown' 'color': 'brown',
'amount': 1.25
} }
response = self.client.post(self.endpoint, data, format='json') response = self.client.post(self.endpoint, data, format='json')
self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(response.status_code, status.HTTP_201_CREATED)
obj = models.DiaperChange.objects.get(pk=response.data['id']) obj = models.DiaperChange.objects.get(pk=response.data['id'])
self.assertTrue(obj.wet)
self.assertTrue(obj.solid)
self.assertEqual(obj.color, data['color']) self.assertEqual(obj.color, data['color'])
self.assertEqual(obj.amount, data['amount'])
@override_settings(TIME_ZONE='US/Eastern') @override_settings(TIME_ZONE='US/Eastern')

View File

@ -16,7 +16,7 @@ class ChildViewSet(viewsets.ModelViewSet):
class DiaperChangeViewSet(viewsets.ModelViewSet): class DiaperChangeViewSet(viewsets.ModelViewSet):
queryset = models.DiaperChange.objects.all() queryset = models.DiaperChange.objects.all()
serializer_class = serializers.DiaperChangeSerializer serializer_class = serializers.DiaperChangeSerializer
filterset_fields = ('child', 'wet', 'solid', 'color') filterset_fields = ('child', 'wet', 'solid', 'color', 'amount')
class FeedingViewSet(viewsets.ModelViewSet): class FeedingViewSet(viewsets.ModelViewSet):

View File

@ -20,7 +20,8 @@
"time": "2017-11-18T16:00:00Z", "time": "2017-11-18T16:00:00Z",
"wet": false, "wet": false,
"solid": true, "solid": true,
"color": "green" "color": "green",
"amount": null
} }
}, },
{ {
@ -32,7 +33,8 @@
"time": "2017-11-18T19:00:00Z", "time": "2017-11-18T19:00:00Z",
"wet": true, "wet": true,
"solid": false, "solid": false,
"color": "" "color": "",
"amount": 2.25
} }
}, },
{ {
@ -44,7 +46,8 @@
"time": "2017-11-17T13:00:00Z", "time": "2017-11-17T13:00:00Z",
"wet": false, "wet": false,
"solid": true, "solid": true,
"color": "green" "color": "green",
"amount": 1.3
} }
}, },
{ {
@ -56,7 +59,8 @@
"time": "2017-11-17T16:00:00Z", "time": "2017-11-17T16:00:00Z",
"wet": false, "wet": false,
"solid": true, "solid": true,
"color": "green" "color": "green",
"amount": null
} }
}, },
{ {
@ -68,7 +72,8 @@
"time": "2017-11-16T15:00:00Z", "time": "2017-11-16T15:00:00Z",
"wet": true, "wet": true,
"solid": false, "solid": false,
"color": "" "color": "",
"amount": null
} }
}, },
{ {
@ -80,7 +85,8 @@
"time": "2017-11-16T18:00:00Z", "time": "2017-11-16T18:00:00Z",
"wet": true, "wet": true,
"solid": false, "solid": false,
"color": "" "color": "",
"amount": 5.4
} }
}, },
{ {
@ -92,7 +98,8 @@
"time": "2017-11-15T15:00:00Z", "time": "2017-11-15T15:00:00Z",
"wet": false, "wet": false,
"solid": true, "solid": true,
"color": "brown" "color": "brown",
"amount": 0.25
} }
}, },
{ {
@ -104,7 +111,8 @@
"time": "2017-11-15T13:00:00Z", "time": "2017-11-15T13:00:00Z",
"wet": true, "wet": true,
"solid": false, "solid": false,
"color": "" "color": "",
"amount": 1.67
} }
}, },
{ {
@ -116,7 +124,8 @@
"time": "2017-11-15T16:00:00Z", "time": "2017-11-15T16:00:00Z",
"wet": true, "wet": true,
"solid": false, "solid": false,
"color": "" "color": "",
"amount": 1.0
} }
}, },
{ {
@ -128,7 +137,8 @@
"time": "2017-11-15T21:00:00Z", "time": "2017-11-15T21:00:00Z",
"wet": true, "wet": true,
"solid": false, "solid": false,
"color": "" "color": "",
"amount": null
} }
}, },
{ {
@ -140,7 +150,8 @@
"time": "2017-11-14T15:00:00Z", "time": "2017-11-14T15:00:00Z",
"wet": true, "wet": true,
"solid": false, "solid": false,
"color": "" "color": "",
"amount": null
} }
}, },
{ {
@ -152,7 +163,8 @@
"time": "2017-11-13T14:00:00Z", "time": "2017-11-13T14:00:00Z",
"wet": true, "wet": true,
"solid": false, "solid": false,
"color": "" "color": "",
"amount": 2.6
} }
}, },
{ {
@ -164,7 +176,8 @@
"time": "2017-11-13T18:00:00Z", "time": "2017-11-13T18:00:00Z",
"wet": true, "wet": true,
"solid": false, "solid": false,
"color": "" "color": "",
"amount": null
} }
}, },
{ {
@ -176,7 +189,8 @@
"time": "2017-11-12T15:00:00Z", "time": "2017-11-12T15:00:00Z",
"wet": true, "wet": true,
"solid": false, "solid": false,
"color": "" "color": "",
"amount": null
} }
}, },
{ {
@ -188,7 +202,8 @@
"time": "2017-11-11T15:00:00Z", "time": "2017-11-11T15:00:00Z",
"wet": true, "wet": true,
"solid": false, "solid": false,
"color": "" "color": "",
"amount": 0.75
} }
}, },
{ {