2017-08-13 13:44:48 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
from rest_framework import viewsets
|
|
|
|
|
2017-08-16 12:49:58 +00:00
|
|
|
from core.models import Child, DiaperChange, Feeding, Note, Sleep, TummyTime
|
2017-08-13 20:26:52 +00:00
|
|
|
from core.utils import filter_by_params
|
2017-08-16 12:49:58 +00:00
|
|
|
from .serializers import (ChildSerializer, DiaperChangeSerializer,
|
2017-08-13 20:48:16 +00:00
|
|
|
FeedingSerializer, NoteSerializer, SleepSerializer,
|
2017-08-13 20:17:18 +00:00
|
|
|
TummyTimeSerializer,)
|
2017-08-13 14:48:16 +00:00
|
|
|
|
|
|
|
|
2017-08-16 12:49:58 +00:00
|
|
|
class ChildViewSet(viewsets.ModelViewSet):
|
|
|
|
queryset = Child.objects.all()
|
|
|
|
serializer_class = ChildSerializer
|
2017-08-13 14:48:16 +00:00
|
|
|
|
2017-08-13 20:15:57 +00:00
|
|
|
def get_queryset(self):
|
2017-08-13 20:26:52 +00:00
|
|
|
params = ['first_name', 'last_name']
|
2017-08-16 12:49:58 +00:00
|
|
|
return filter_by_params(self.request, Child, params)
|
2017-08-13 20:15:57 +00:00
|
|
|
|
2017-08-13 14:48:16 +00:00
|
|
|
|
2017-08-13 19:51:25 +00:00
|
|
|
class DiaperChangeViewSet(viewsets.ModelViewSet):
|
|
|
|
queryset = DiaperChange.objects.all()
|
|
|
|
serializer_class = DiaperChangeSerializer
|
|
|
|
|
2017-08-13 20:15:57 +00:00
|
|
|
def get_queryset(self):
|
2017-08-13 20:26:52 +00:00
|
|
|
params = ['baby__last_name', 'wet', 'solid', 'color']
|
|
|
|
return filter_by_params(self.request, DiaperChange, params)
|
2017-08-13 20:15:57 +00:00
|
|
|
|
2017-08-13 19:51:25 +00:00
|
|
|
|
2017-08-13 15:59:14 +00:00
|
|
|
class FeedingViewSet(viewsets.ModelViewSet):
|
|
|
|
queryset = Feeding.objects.all()
|
|
|
|
serializer_class = FeedingSerializer
|
|
|
|
|
2017-08-13 20:15:57 +00:00
|
|
|
def get_queryset(self):
|
2017-08-13 20:26:52 +00:00
|
|
|
params = ['baby__last_name', 'type', 'method']
|
|
|
|
return filter_by_params(self.request, Feeding, params)
|
2017-08-13 20:15:57 +00:00
|
|
|
|
2017-08-13 15:59:14 +00:00
|
|
|
|
2017-08-13 20:48:16 +00:00
|
|
|
class NoteViewSet(viewsets.ModelViewSet):
|
|
|
|
queryset = Note.objects.all()
|
|
|
|
serializer_class = NoteSerializer
|
|
|
|
|
|
|
|
def get_queryset(self):
|
|
|
|
params = ['baby__last_name']
|
|
|
|
return filter_by_params(self.request, Note, params)
|
|
|
|
|
|
|
|
|
2017-08-13 14:48:16 +00:00
|
|
|
class SleepViewSet(viewsets.ModelViewSet):
|
|
|
|
queryset = Sleep.objects.all()
|
|
|
|
serializer_class = SleepSerializer
|
2017-08-13 15:59:14 +00:00
|
|
|
|
2017-08-13 20:15:57 +00:00
|
|
|
def get_queryset(self):
|
2017-08-13 20:26:52 +00:00
|
|
|
params = ['baby__last_name']
|
|
|
|
return filter_by_params(self.request, Sleep, params)
|
2017-08-13 20:15:57 +00:00
|
|
|
|
2017-08-13 15:59:14 +00:00
|
|
|
|
2017-08-13 19:05:44 +00:00
|
|
|
class TummyTimeViewSet(viewsets.ModelViewSet):
|
|
|
|
queryset = TummyTime.objects.all()
|
|
|
|
serializer_class = TummyTimeSerializer
|
|
|
|
|
2017-08-13 20:15:57 +00:00
|
|
|
def get_queryset(self):
|
2017-08-13 20:26:52 +00:00
|
|
|
params = ['baby__last_name']
|
|
|
|
return filter_by_params(self.request, TummyTime, params)
|