mybuddy/api/serializers.py

79 lines
1.9 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from rest_framework import serializers
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
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-08-18 12:08:23 +00:00
fields = ('first_name', 'last_name', 'birth_date', 'slug')
lookup_field = 'slug'
2017-08-13 14:48:16 +00:00
2017-08-13 19:51:25 +00:00
class DiaperChangeSerializer(serializers.HyperlinkedModelSerializer):
child = ChildSerializer()
2017-08-13 19:51:25 +00:00
class Meta:
2017-11-10 02:15:09 +00:00
model = models.DiaperChange
fields = ('child', 'time', 'wet', 'solid', 'color')
2017-08-13 19:51:25 +00:00
2017-08-13 15:59:14 +00:00
class FeedingSerializer(serializers.HyperlinkedModelSerializer):
child = ChildSerializer()
2017-08-13 15:59:14 +00:00
class Meta:
2017-11-10 02:15:09 +00:00
model = models.Feeding
fields = ('child', 'start', 'end', 'duration', 'type', 'method',
'amount')
2017-08-13 15:59:14 +00:00
2017-08-13 20:48:16 +00:00
class NoteSerializer(serializers.HyperlinkedModelSerializer):
child = ChildSerializer()
2017-08-13 20:48:16 +00:00
class Meta:
2017-11-10 02:15:09 +00:00
model = models.Note
fields = ('child', 'note', 'time')
2017-08-13 20:48:16 +00:00
2017-08-13 14:48:16 +00:00
class SleepSerializer(serializers.HyperlinkedModelSerializer):
child = ChildSerializer()
2017-08-13 14:48:16 +00:00
class Meta:
2017-11-10 02:15:09 +00:00
model = models.Sleep
fields = ('child', 'start', 'end', 'duration')
2017-08-13 15:59:14 +00:00
class TimerSerializer(serializers.HyperlinkedModelSerializer):
user = UserSerializer()
class Meta:
2017-11-10 02:15:09 +00:00
model = models.Timer
fields = ('name', 'start', 'end', 'duration', 'active', 'user')
2017-08-13 19:05:44 +00:00
class TummyTimeSerializer(serializers.HyperlinkedModelSerializer):
child = ChildSerializer()
2017-08-13 19:05:44 +00:00
class Meta:
2017-11-10 02:15:09 +00:00
model = models.TummyTime
fields = ('child', 'start', 'end', 'duration', 'milestone')
2017-11-10 02:15:09 +00:00
class WeightSerializer(serializers.HyperlinkedModelSerializer):
child = ChildSerializer()
class Meta:
model = models.Weight
fields = ('child', 'weight', 'date')