mybuddy/api/views.py

102 lines
3.2 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
from rest_framework import viewsets
from rest_framework.decorators import action
from rest_framework.response import Response
2017-11-10 02:15:09 +00:00
from core import models
from . import serializers, filters
from .mixins import TimerFieldSupportMixin
2017-08-13 14:48:16 +00:00
2022-02-27 19:36:31 +00:00
2017-08-16 12:49:58 +00:00
class ChildViewSet(viewsets.ModelViewSet):
2017-11-10 02:15:09 +00:00
queryset = models.Child.objects.all()
serializer_class = serializers.ChildSerializer
2022-02-10 00:00:30 +00:00
lookup_field = "slug"
filterset_fields = ("first_name", "last_name", "slug", "birth_date")
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):
2017-11-10 02:15:09 +00:00
queryset = models.DiaperChange.objects.all()
serializer_class = serializers.DiaperChangeSerializer
filterset_class = filters.DiaperChangeFilter
2017-08-13 20:15:57 +00:00
2017-08-13 19:51:25 +00:00
class FeedingViewSet(TimerFieldSupportMixin, viewsets.ModelViewSet):
2017-11-10 02:15:09 +00:00
queryset = models.Feeding.objects.all()
serializer_class = serializers.FeedingSerializer
filterset_class = filters.FeedingFilter
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):
2017-11-10 02:15:09 +00:00
queryset = models.Note.objects.all()
serializer_class = serializers.NoteSerializer
filterset_class = filters.NoteFilter
2017-08-13 20:48:16 +00:00
class SleepViewSet(TimerFieldSupportMixin, viewsets.ModelViewSet):
2017-11-10 02:15:09 +00:00
queryset = models.Sleep.objects.all()
serializer_class = serializers.SleepSerializer
filterset_class = filters.SleepFilter
2017-08-13 20:15:57 +00:00
2017-08-13 15:59:14 +00:00
2019-05-17 05:13:14 +00:00
class TemperatureViewSet(viewsets.ModelViewSet):
queryset = models.Temperature.objects.all()
serializer_class = serializers.TemperatureSerializer
filterset_class = filters.TemperatureFilter
2019-05-17 05:13:14 +00:00
class TimerViewSet(viewsets.ModelViewSet):
2017-11-10 02:15:09 +00:00
queryset = models.Timer.objects.all()
serializer_class = serializers.TimerSerializer
filterset_class = filters.TimerFilter
2022-02-10 00:00:30 +00:00
@action(detail=True, methods=["patch"])
def stop(self, request, pk=None):
timer = self.get_object()
timer.stop()
return Response(self.serializer_class(timer).data)
2022-02-10 00:00:30 +00:00
@action(detail=True, methods=["patch"])
def restart(self, request, pk=None):
timer = self.get_object()
timer.restart()
return Response(self.serializer_class(timer).data)
class TummyTimeViewSet(TimerFieldSupportMixin, viewsets.ModelViewSet):
2017-11-10 02:15:09 +00:00
queryset = models.TummyTime.objects.all()
serializer_class = serializers.TummyTimeSerializer
filterset_class = filters.TummyTimeFilter
2017-11-10 02:15:09 +00:00
class WeightViewSet(viewsets.ModelViewSet):
queryset = models.Weight.objects.all()
serializer_class = serializers.WeightSerializer
2022-02-10 00:00:30 +00:00
filterset_fields = ("child", "date")
2021-12-30 03:32:55 +00:00
class HeightViewSet(viewsets.ModelViewSet):
queryset = models.Height.objects.all()
serializer_class = serializers.HeightSerializer
2022-02-10 00:00:30 +00:00
filterset_fields = ("child", "date")
2021-12-30 03:32:55 +00:00
class HeadCircumferenceViewSet(viewsets.ModelViewSet):
queryset = models.HeadCircumference.objects.all()
serializer_class = serializers.HeadCircumferenceSerializer
2022-02-10 00:00:30 +00:00
filterset_fields = ("child", "date")
2021-12-30 03:32:55 +00:00
class BMIViewSet(viewsets.ModelViewSet):
queryset = models.BMI.objects.all()
serializer_class = serializers.BMISerializer
2022-02-10 00:00:30 +00:00
filterset_fields = ("child", "date")
2022-02-15 21:24:13 +00:00
2022-02-17 23:22:01 +00:00
2022-02-15 21:24:13 +00:00
class TagsViewSet(viewsets.ModelViewSet):
queryset = models.Tag.objects.all()
2022-02-15 21:24:13 +00:00
serializer_class = serializers.TagsSerializer
lookup_field = "slug"
2022-02-17 23:22:01 +00:00
filterset_fields = ("last_used", "name")