2017-08-13 13:44:48 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from rest_framework import serializers
|
|
|
|
|
2017-10-21 21:35:34 +00:00
|
|
|
from django.contrib.auth.models import User
|
|
|
|
|
2017-11-10 02:15:09 +00:00
|
|
|
from core import models
|
2017-08-13 14:48:16 +00:00
|
|
|
|
|
|
|
|
2017-12-05 21:31:37 +00:00
|
|
|
class CoreModelSerializer(serializers.HyperlinkedModelSerializer):
|
|
|
|
"""
|
|
|
|
Provide the child link (used by most core models) and run model clean()
|
|
|
|
methods during POST operations.
|
|
|
|
"""
|
|
|
|
child = serializers.PrimaryKeyRelatedField(
|
|
|
|
queryset=models.Child.objects.all())
|
|
|
|
|
|
|
|
def validate(self, attrs):
|
|
|
|
instance = self.Meta.model(**attrs)
|
|
|
|
instance.clean()
|
|
|
|
return attrs
|
|
|
|
|
|
|
|
|
2017-10-21 21:35:34 +00:00
|
|
|
class UserSerializer(serializers.ModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = User
|
|
|
|
fields = ('id', 'username')
|
|
|
|
|
|
|
|
|
2017-08-16 12:49:58 +00:00
|
|
|
class ChildSerializer(serializers.HyperlinkedModelSerializer):
|
2017-08-13 14:48:16 +00:00
|
|
|
class Meta:
|
2017-11-10 02:15:09 +00:00
|
|
|
model = models.Child
|
2017-12-05 21:31:37 +00:00
|
|
|
fields = ('id', 'first_name', 'last_name', 'birth_date', 'slug')
|
2017-08-18 12:08:23 +00:00
|
|
|
lookup_field = 'slug'
|
2017-08-13 14:48:16 +00:00
|
|
|
|
|
|
|
|
2017-12-05 21:31:37 +00:00
|
|
|
class DiaperChangeSerializer(CoreModelSerializer):
|
2017-08-13 19:51:25 +00:00
|
|
|
class Meta:
|
2017-11-10 02:15:09 +00:00
|
|
|
model = models.DiaperChange
|
2020-01-26 22:30:00 +00:00
|
|
|
fields = ('id', 'child', 'time', 'wet', 'solid', 'color', 'amount')
|
2017-08-13 19:51:25 +00:00
|
|
|
|
2017-08-17 16:17:51 +00:00
|
|
|
|
2017-12-05 21:31:37 +00:00
|
|
|
class FeedingSerializer(CoreModelSerializer):
|
2017-08-13 15:59:14 +00:00
|
|
|
class Meta:
|
2017-11-10 02:15:09 +00:00
|
|
|
model = models.Feeding
|
2017-12-05 21:31:37 +00:00
|
|
|
fields = ('id', 'child', 'start', 'end', 'duration', 'type', 'method',
|
2017-08-16 22:07:25 +00:00
|
|
|
'amount')
|
2017-08-13 15:59:14 +00:00
|
|
|
|
|
|
|
|
2017-12-05 21:31:37 +00:00
|
|
|
class NoteSerializer(CoreModelSerializer):
|
2017-08-13 20:48:16 +00:00
|
|
|
class Meta:
|
2017-11-10 02:15:09 +00:00
|
|
|
model = models.Note
|
2017-12-05 21:31:37 +00:00
|
|
|
fields = ('id', 'child', 'note', 'time')
|
2017-08-13 20:48:16 +00:00
|
|
|
|
2017-08-17 16:17:51 +00:00
|
|
|
|
2017-12-05 21:31:37 +00:00
|
|
|
class SleepSerializer(CoreModelSerializer):
|
2017-08-13 14:48:16 +00:00
|
|
|
class Meta:
|
2017-11-10 02:15:09 +00:00
|
|
|
model = models.Sleep
|
2017-12-05 21:31:37 +00:00
|
|
|
fields = ('id', 'child', 'start', 'end', 'duration')
|
2017-08-13 15:59:14 +00:00
|
|
|
|
|
|
|
|
2019-05-17 05:13:14 +00:00
|
|
|
class TemperatureSerializer(CoreModelSerializer):
|
|
|
|
class Meta:
|
|
|
|
model = models.Temperature
|
|
|
|
fields = ('id', 'child', 'temperature', 'time')
|
|
|
|
|
|
|
|
|
2017-12-05 21:31:37 +00:00
|
|
|
class TimerSerializer(CoreModelSerializer):
|
|
|
|
user = serializers.PrimaryKeyRelatedField(queryset=User.objects.all())
|
2017-10-21 21:35:34 +00:00
|
|
|
|
2017-08-16 22:33:02 +00:00
|
|
|
class Meta:
|
2017-11-10 02:15:09 +00:00
|
|
|
model = models.Timer
|
2017-12-05 21:31:37 +00:00
|
|
|
fields = ('id', 'name', 'start', 'end', 'duration', 'active', 'user')
|
2017-08-16 22:33:02 +00:00
|
|
|
|
|
|
|
|
2017-12-05 21:31:37 +00:00
|
|
|
class TummyTimeSerializer(CoreModelSerializer):
|
2017-08-13 19:05:44 +00:00
|
|
|
class Meta:
|
2017-11-10 02:15:09 +00:00
|
|
|
model = models.TummyTime
|
2017-12-05 21:31:37 +00:00
|
|
|
fields = ('id', 'child', 'start', 'end', 'duration', 'milestone')
|
2017-11-10 02:15:09 +00:00
|
|
|
|
|
|
|
|
2017-12-05 21:31:37 +00:00
|
|
|
class WeightSerializer(CoreModelSerializer):
|
2017-11-10 02:15:09 +00:00
|
|
|
class Meta:
|
|
|
|
model = models.Weight
|
2017-12-05 21:31:37 +00:00
|
|
|
fields = ('id', 'child', 'weight', 'date')
|