mirror of https://github.com/snachodog/mybuddy.git
Add order-able fields and defaults
This commit is contained in:
parent
ac19f30173
commit
bf2884f544
28
api/views.py
28
api/views.py
|
@ -16,6 +16,8 @@ class BMIViewSet(viewsets.ModelViewSet):
|
||||||
queryset = models.BMI.objects.all()
|
queryset = models.BMI.objects.all()
|
||||||
serializer_class = serializers.BMISerializer
|
serializer_class = serializers.BMISerializer
|
||||||
filterset_fields = ("child", "date")
|
filterset_fields = ("child", "date")
|
||||||
|
ordering_fields = ("child", "date")
|
||||||
|
ordering = "-date"
|
||||||
|
|
||||||
def get_view_name(self):
|
def get_view_name(self):
|
||||||
"""
|
"""
|
||||||
|
@ -32,48 +34,64 @@ class ChildViewSet(viewsets.ModelViewSet):
|
||||||
serializer_class = serializers.ChildSerializer
|
serializer_class = serializers.ChildSerializer
|
||||||
lookup_field = "slug"
|
lookup_field = "slug"
|
||||||
filterset_fields = ("first_name", "last_name", "slug", "birth_date")
|
filterset_fields = ("first_name", "last_name", "slug", "birth_date")
|
||||||
|
ordering_fields = ("birth_date", "first_name", "last_name", "slug")
|
||||||
|
ordering = "-birth_date"
|
||||||
|
|
||||||
|
|
||||||
class DiaperChangeViewSet(viewsets.ModelViewSet):
|
class DiaperChangeViewSet(viewsets.ModelViewSet):
|
||||||
queryset = models.DiaperChange.objects.all()
|
queryset = models.DiaperChange.objects.all()
|
||||||
serializer_class = serializers.DiaperChangeSerializer
|
serializer_class = serializers.DiaperChangeSerializer
|
||||||
filterset_class = filters.DiaperChangeFilter
|
filterset_class = filters.DiaperChangeFilter
|
||||||
|
ordering_fields = ("amount", "time")
|
||||||
|
ordering = "-time"
|
||||||
|
|
||||||
|
|
||||||
class FeedingViewSet(viewsets.ModelViewSet):
|
class FeedingViewSet(viewsets.ModelViewSet):
|
||||||
queryset = models.Feeding.objects.all()
|
queryset = models.Feeding.objects.all()
|
||||||
serializer_class = serializers.FeedingSerializer
|
serializer_class = serializers.FeedingSerializer
|
||||||
filterset_class = filters.FeedingFilter
|
filterset_class = filters.FeedingFilter
|
||||||
|
ordering_fields = ("amount", "duration", "end", "start")
|
||||||
|
ordering = "-end"
|
||||||
|
|
||||||
|
|
||||||
class HeadCircumferenceViewSet(viewsets.ModelViewSet):
|
class HeadCircumferenceViewSet(viewsets.ModelViewSet):
|
||||||
queryset = models.HeadCircumference.objects.all()
|
queryset = models.HeadCircumference.objects.all()
|
||||||
serializer_class = serializers.HeadCircumferenceSerializer
|
serializer_class = serializers.HeadCircumferenceSerializer
|
||||||
filterset_fields = ("child", "date")
|
filterset_fields = ("child", "date")
|
||||||
|
ordering_fields = ("date", "head_circumference")
|
||||||
|
ordering = "-date"
|
||||||
|
|
||||||
|
|
||||||
class HeightViewSet(viewsets.ModelViewSet):
|
class HeightViewSet(viewsets.ModelViewSet):
|
||||||
queryset = models.Height.objects.all()
|
queryset = models.Height.objects.all()
|
||||||
serializer_class = serializers.HeightSerializer
|
serializer_class = serializers.HeightSerializer
|
||||||
filterset_fields = ("child", "date")
|
filterset_fields = ("child", "date")
|
||||||
|
ordering_fields = ("date", "height")
|
||||||
|
ordering = "-date"
|
||||||
|
|
||||||
|
|
||||||
class NoteViewSet(viewsets.ModelViewSet):
|
class NoteViewSet(viewsets.ModelViewSet):
|
||||||
queryset = models.Note.objects.all()
|
queryset = models.Note.objects.all()
|
||||||
serializer_class = serializers.NoteSerializer
|
serializer_class = serializers.NoteSerializer
|
||||||
filterset_class = filters.NoteFilter
|
filterset_class = filters.NoteFilter
|
||||||
|
ordering_fields = "time"
|
||||||
|
ordering = "-time"
|
||||||
|
|
||||||
|
|
||||||
class PumpingViewSet(viewsets.ModelViewSet):
|
class PumpingViewSet(viewsets.ModelViewSet):
|
||||||
queryset = models.Pumping.objects.all()
|
queryset = models.Pumping.objects.all()
|
||||||
serializer_class = serializers.PumpingSerializer
|
serializer_class = serializers.PumpingSerializer
|
||||||
filterset_class = filters.PumpingFilter
|
filterset_class = filters.PumpingFilter
|
||||||
|
ordering_fields = ("amount", "time")
|
||||||
|
ordering = "-time"
|
||||||
|
|
||||||
|
|
||||||
class SleepViewSet(viewsets.ModelViewSet):
|
class SleepViewSet(viewsets.ModelViewSet):
|
||||||
queryset = models.Sleep.objects.all()
|
queryset = models.Sleep.objects.all()
|
||||||
serializer_class = serializers.SleepSerializer
|
serializer_class = serializers.SleepSerializer
|
||||||
filterset_class = filters.SleepFilter
|
filterset_class = filters.SleepFilter
|
||||||
|
ordering_fields = ("duration", "end", "start")
|
||||||
|
ordering = "-end"
|
||||||
|
|
||||||
|
|
||||||
class TagViewSet(viewsets.ModelViewSet):
|
class TagViewSet(viewsets.ModelViewSet):
|
||||||
|
@ -81,18 +99,24 @@ class TagViewSet(viewsets.ModelViewSet):
|
||||||
serializer_class = serializers.TagSerializer
|
serializer_class = serializers.TagSerializer
|
||||||
lookup_field = "slug"
|
lookup_field = "slug"
|
||||||
filterset_fields = ("last_used", "name")
|
filterset_fields = ("last_used", "name")
|
||||||
|
ordering_fields = ("last_used", "name", "slug")
|
||||||
|
ordering = "name"
|
||||||
|
|
||||||
|
|
||||||
class TemperatureViewSet(viewsets.ModelViewSet):
|
class TemperatureViewSet(viewsets.ModelViewSet):
|
||||||
queryset = models.Temperature.objects.all()
|
queryset = models.Temperature.objects.all()
|
||||||
serializer_class = serializers.TemperatureSerializer
|
serializer_class = serializers.TemperatureSerializer
|
||||||
filterset_class = filters.TemperatureFilter
|
filterset_class = filters.TemperatureFilter
|
||||||
|
ordering_fields = ("temperature", "time")
|
||||||
|
ordering = "-time"
|
||||||
|
|
||||||
|
|
||||||
class TimerViewSet(viewsets.ModelViewSet):
|
class TimerViewSet(viewsets.ModelViewSet):
|
||||||
queryset = models.Timer.objects.all()
|
queryset = models.Timer.objects.all()
|
||||||
serializer_class = serializers.TimerSerializer
|
serializer_class = serializers.TimerSerializer
|
||||||
filterset_class = filters.TimerFilter
|
filterset_class = filters.TimerFilter
|
||||||
|
ordering_fields = ("duration", "end", "start")
|
||||||
|
ordering = "-start"
|
||||||
|
|
||||||
@action(detail=True, methods=["patch"])
|
@action(detail=True, methods=["patch"])
|
||||||
def stop(self, request, pk=None):
|
def stop(self, request, pk=None):
|
||||||
|
@ -111,12 +135,16 @@ class TummyTimeViewSet(viewsets.ModelViewSet):
|
||||||
queryset = models.TummyTime.objects.all()
|
queryset = models.TummyTime.objects.all()
|
||||||
serializer_class = serializers.TummyTimeSerializer
|
serializer_class = serializers.TummyTimeSerializer
|
||||||
filterset_class = filters.TummyTimeFilter
|
filterset_class = filters.TummyTimeFilter
|
||||||
|
ordering_fields = ("duration", "end", "start")
|
||||||
|
ordering = "-start"
|
||||||
|
|
||||||
|
|
||||||
class WeightViewSet(viewsets.ModelViewSet):
|
class WeightViewSet(viewsets.ModelViewSet):
|
||||||
queryset = models.Weight.objects.all()
|
queryset = models.Weight.objects.all()
|
||||||
serializer_class = serializers.WeightSerializer
|
serializer_class = serializers.WeightSerializer
|
||||||
filterset_fields = ("child", "date")
|
filterset_fields = ("child", "date")
|
||||||
|
ordering_fields = ("date", "weight")
|
||||||
|
ordering = "-date"
|
||||||
|
|
||||||
|
|
||||||
class ProfileView(views.APIView):
|
class ProfileView(views.APIView):
|
||||||
|
|
1142
openapi-schema.yml
1142
openapi-schema.yml
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue