mybuddy/api/views.py

55 lines
1.6 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from rest_framework import viewsets
from core.models import (Child, DiaperChange, Feeding, Note, Sleep, Timer,
TummyTime)
2017-08-16 12:49:58 +00:00
from .serializers import (ChildSerializer, DiaperChangeSerializer,
2017-08-13 20:48:16 +00:00
FeedingSerializer, NoteSerializer, SleepSerializer,
TimerSerializer, 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-18 12:08:23 +00:00
lookup_field = 'slug'
filter_fields = ('first_name', 'last_name', 'slug')
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
filter_fields = ('child', 'wet', 'solid', 'color')
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
filter_fields = ('child', 'type', 'method')
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
filter_fields = ('child',)
2017-08-13 20:48:16 +00:00
2017-08-13 14:48:16 +00:00
class SleepViewSet(viewsets.ModelViewSet):
queryset = Sleep.objects.all()
serializer_class = SleepSerializer
filter_fields = ('child',)
2017-08-13 20:15:57 +00:00
2017-08-13 15:59:14 +00:00
class TimerViewSet(viewsets.ModelViewSet):
queryset = Timer.objects.all()
serializer_class = TimerSerializer
filter_fields = ('active', 'user')
2017-08-13 19:05:44 +00:00
class TummyTimeViewSet(viewsets.ModelViewSet):
queryset = TummyTime.objects.all()
serializer_class = TummyTimeSerializer
filter_fields = ('child',)