mirror of https://github.com/snachodog/mybuddy.git
Experimental changes
This commit is contained in:
parent
d5bbbd4ee4
commit
a6433732b6
|
@ -9,6 +9,7 @@ from django.utils import timezone
|
||||||
from taggit.serializers import TagListSerializerField, TaggitSerializer
|
from taggit.serializers import TagListSerializerField, TaggitSerializer
|
||||||
|
|
||||||
from core import models
|
from core import models
|
||||||
|
from babybuddy import models as babybuddy_models
|
||||||
|
|
||||||
|
|
||||||
class CoreModelSerializer(serializers.HyperlinkedModelSerializer):
|
class CoreModelSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
@ -268,3 +269,9 @@ class WeightSerializer(CoreModelSerializer, TaggableSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = models.Weight
|
model = models.Weight
|
||||||
fields = ("id", "child", "weight", "date", "notes", "tags")
|
fields = ("id", "child", "weight", "date", "notes", "tags")
|
||||||
|
|
||||||
|
|
||||||
|
class ProfileSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = babybuddy_models.Settings
|
||||||
|
fields = ("user", "language")
|
||||||
|
|
19
api/urls.py
19
api/urls.py
|
@ -1,4 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
from typing import NamedTuple, Optional, Any
|
||||||
|
|
||||||
from django.urls import include, path
|
from django.urls import include, path
|
||||||
from rest_framework import routers
|
from rest_framework import routers
|
||||||
from rest_framework.schemas import get_schema_view
|
from rest_framework.schemas import get_schema_view
|
||||||
|
@ -21,11 +23,12 @@ router.register(r"timers", views.TimerViewSet)
|
||||||
router.register(r"tummy-times", views.TummyTimeViewSet)
|
router.register(r"tummy-times", views.TummyTimeViewSet)
|
||||||
router.register(r"weight", views.WeightViewSet)
|
router.register(r"weight", views.WeightViewSet)
|
||||||
|
|
||||||
app_name = "api"
|
class ExtraUrl(NamedTuple):
|
||||||
|
view: Any
|
||||||
|
name: Optional[str] = None
|
||||||
|
|
||||||
urlpatterns = [
|
extra_api_urls = [
|
||||||
path("api/", include(router.urls)),
|
path("api/profile", views.ProfileView.as_view()),
|
||||||
path("api/auth/", include("rest_framework.urls", namespace="rest_framework")),
|
|
||||||
path(
|
path(
|
||||||
"api/schema",
|
"api/schema",
|
||||||
get_schema_view(
|
get_schema_view(
|
||||||
|
@ -36,3 +39,11 @@ urlpatterns = [
|
||||||
name="openapi-schema",
|
name="openapi-schema",
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
app_name = "api"
|
||||||
|
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path("api/", include(router.urls + list(extra_api_urls))),
|
||||||
|
path("api/auth/", include("rest_framework.urls", namespace="rest_framework")),
|
||||||
|
] + extra_api_urls
|
||||||
|
|
19
api/views.py
19
api/views.py
|
@ -1,9 +1,12 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from rest_framework import viewsets
|
from django.shortcuts import get_object_or_404
|
||||||
|
|
||||||
|
from rest_framework import viewsets, views
|
||||||
from rest_framework.decorators import action
|
from rest_framework.decorators import action
|
||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
|
|
||||||
from core import models
|
from core import models
|
||||||
|
from babybuddy import models as babybuddy_models
|
||||||
|
|
||||||
from . import serializers, filters
|
from . import serializers, filters
|
||||||
|
|
||||||
|
@ -113,3 +116,17 @@ 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")
|
||||||
|
|
||||||
|
|
||||||
|
class ProfileView(views.APIView):
|
||||||
|
basename = "profile"
|
||||||
|
queryset = babybuddy_models.Settings.objects.all()
|
||||||
|
serializer_class = serializers.ProfileSerializer
|
||||||
|
|
||||||
|
def get(self, request):
|
||||||
|
settings = get_object_or_404(
|
||||||
|
babybuddy_models.Settings.objects,
|
||||||
|
user=request.user
|
||||||
|
)
|
||||||
|
serializer = self.serializer_class(settings)
|
||||||
|
return Response(serializer.data)
|
||||||
|
|
Loading…
Reference in New Issue