Update `api` app for latest core model changes

This commit is contained in:
Christopher C. Wells 2020-01-30 13:55:33 -08:00 committed by Christopher Charbonneau Wells
parent 6ba6e429cd
commit 8421b14088
3 changed files with 14 additions and 6 deletions

View File

@ -29,7 +29,8 @@ class UserSerializer(serializers.ModelSerializer):
class ChildSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = models.Child
fields = ('id', 'first_name', 'last_name', 'birth_date', 'slug')
fields = ('id', 'first_name', 'last_name', 'birth_date', 'slug',
'picture')
lookup_field = 'slug'
@ -55,7 +56,7 @@ class NoteSerializer(CoreModelSerializer):
class SleepSerializer(CoreModelSerializer):
class Meta:
model = models.Sleep
fields = ('id', 'child', 'start', 'end', 'duration')
fields = ('id', 'child', 'start', 'end', 'duration', 'nap')
class TemperatureSerializer(CoreModelSerializer):
@ -65,11 +66,15 @@ class TemperatureSerializer(CoreModelSerializer):
class TimerSerializer(CoreModelSerializer):
child = serializers.PrimaryKeyRelatedField(
allow_null=True, allow_empty=True, queryset=models.Child.objects.all(),
required=False)
user = serializers.PrimaryKeyRelatedField(queryset=User.objects.all())
class Meta:
model = models.Timer
fields = ('id', 'name', 'start', 'end', 'duration', 'active', 'user')
fields = ('id', 'child', 'name', 'start', 'end', 'duration', 'active',
'user')
class TummyTimeSerializer(CoreModelSerializer):

View File

@ -24,7 +24,8 @@ class ChildAPITestCase(APITestCase):
'first_name': 'Fake',
'last_name': 'Child',
'birth_date': '2017-11-11',
'slug': 'fake-child'
'slug': 'fake-child',
'picture': None
})
def test_options(self):
@ -180,7 +181,8 @@ class SleepAPITestCase(APITestCase):
'child': 1,
'start': '2017-11-18T19:00:00-05:00',
'end': '2017-11-18T23:00:00-05:00',
'duration': '04:00:00'
'duration': '04:00:00',
'nap': False
})
def test_options(self):
@ -248,6 +250,7 @@ class TimerAPITestCase(APITestCase):
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.data['results'][0], {
'id': 1,
'child': None,
'name': 'Fake timer',
'start': '2017-11-17T23:30:00-05:00',
'end': '2017-11-18T00:30:00-05:00',

View File

@ -46,7 +46,7 @@ class TemperatureViewSet(viewsets.ModelViewSet):
class TimerViewSet(viewsets.ModelViewSet):
queryset = models.Timer.objects.all()
serializer_class = serializers.TimerSerializer
filterset_fields = ('active', 'user')
filterset_fields = ('child', 'active', 'user')
class TummyTimeViewSet(viewsets.ModelViewSet):