Fix API child and user serializers.

The HyperlinkedIdentityField got broken somewhere along the way here and I am not sure, but this is not a priority right now.
This commit is contained in:
Christopher Charbonneau Wells 2017-10-21 17:35:34 -04:00
parent 76adaa727c
commit 8eef1574e4
2 changed files with 20 additions and 10 deletions

View File

@ -3,10 +3,18 @@ from __future__ import unicode_literals
from rest_framework import serializers from rest_framework import serializers
from django.contrib.auth.models import User
from core.models import (Child, DiaperChange, Feeding, Note, Sleep, Timer, from core.models import (Child, DiaperChange, Feeding, Note, Sleep, Timer,
TummyTime) TummyTime)
class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = ('id', 'username')
class ChildSerializer(serializers.HyperlinkedModelSerializer): class ChildSerializer(serializers.HyperlinkedModelSerializer):
class Meta: class Meta:
model = Child model = Child
@ -15,7 +23,7 @@ class ChildSerializer(serializers.HyperlinkedModelSerializer):
class DiaperChangeSerializer(serializers.HyperlinkedModelSerializer): class DiaperChangeSerializer(serializers.HyperlinkedModelSerializer):
child = serializers.HyperlinkedIdentityField(view_name='api:child-detail') child = ChildSerializer()
class Meta: class Meta:
model = DiaperChange model = DiaperChange
@ -23,7 +31,7 @@ class DiaperChangeSerializer(serializers.HyperlinkedModelSerializer):
class FeedingSerializer(serializers.HyperlinkedModelSerializer): class FeedingSerializer(serializers.HyperlinkedModelSerializer):
child = serializers.HyperlinkedIdentityField(view_name='api:child-detail') child = ChildSerializer()
class Meta: class Meta:
model = Feeding model = Feeding
@ -32,7 +40,7 @@ class FeedingSerializer(serializers.HyperlinkedModelSerializer):
class NoteSerializer(serializers.HyperlinkedModelSerializer): class NoteSerializer(serializers.HyperlinkedModelSerializer):
child = serializers.HyperlinkedIdentityField(view_name='api:child-detail') child = ChildSerializer()
class Meta: class Meta:
model = Note model = Note
@ -40,7 +48,7 @@ class NoteSerializer(serializers.HyperlinkedModelSerializer):
class SleepSerializer(serializers.HyperlinkedModelSerializer): class SleepSerializer(serializers.HyperlinkedModelSerializer):
child = serializers.HyperlinkedIdentityField(view_name='api:child-detail') child = ChildSerializer()
class Meta: class Meta:
model = Sleep model = Sleep
@ -48,13 +56,15 @@ class SleepSerializer(serializers.HyperlinkedModelSerializer):
class TimerSerializer(serializers.HyperlinkedModelSerializer): class TimerSerializer(serializers.HyperlinkedModelSerializer):
user = UserSerializer()
class Meta: class Meta:
model = Timer model = Timer
fields = ('name', 'start', 'end', 'duration', 'active', 'user') fields = ('name', 'start', 'end', 'duration', 'active', 'user')
class TummyTimeSerializer(serializers.HyperlinkedModelSerializer): class TummyTimeSerializer(serializers.HyperlinkedModelSerializer):
child = serializers.HyperlinkedIdentityField(view_name='api:child-detail') child = ChildSerializer()
class Meta: class Meta:
model = TummyTime model = TummyTime

View File

@ -27,7 +27,7 @@ class DiaperChangeViewSet(viewsets.ModelViewSet):
serializer_class = DiaperChangeSerializer serializer_class = DiaperChangeSerializer
def get_queryset(self): def get_queryset(self):
params = ['child__last_name', 'wet', 'solid', 'color'] params = ['child__slug', 'wet', 'solid', 'color']
return filter_by_params(self.request, DiaperChange, params) return filter_by_params(self.request, DiaperChange, params)
@ -36,7 +36,7 @@ class FeedingViewSet(viewsets.ModelViewSet):
serializer_class = FeedingSerializer serializer_class = FeedingSerializer
def get_queryset(self): def get_queryset(self):
params = ['child__last_name', 'type', 'method', 'amount'] params = ['child__slug', 'type', 'method', 'amount']
return filter_by_params(self.request, Feeding, params) return filter_by_params(self.request, Feeding, params)
@ -45,7 +45,7 @@ class NoteViewSet(viewsets.ModelViewSet):
serializer_class = NoteSerializer serializer_class = NoteSerializer
def get_queryset(self): def get_queryset(self):
params = ['child__last_name'] params = ['child__slug']
return filter_by_params(self.request, Note, params) return filter_by_params(self.request, Note, params)
@ -54,7 +54,7 @@ class SleepViewSet(viewsets.ModelViewSet):
serializer_class = SleepSerializer serializer_class = SleepSerializer
def get_queryset(self): def get_queryset(self):
params = ['child__last_name'] params = ['child__slug']
return filter_by_params(self.request, Sleep, params) return filter_by_params(self.request, Sleep, params)
@ -72,5 +72,5 @@ class TummyTimeViewSet(viewsets.ModelViewSet):
serializer_class = TummyTimeSerializer serializer_class = TummyTimeSerializer
def get_queryset(self): def get_queryset(self):
params = ['child__last_name'] params = ['child__slug']
return filter_by_params(self.request, TummyTime, params) return filter_by_params(self.request, TummyTime, params)