2023-09-10 15:32:07 +00:00
|
|
|
from django.shortcuts import render
|
2023-09-12 15:07:47 +00:00
|
|
|
from rest_framework import pagination, status, viewsets
|
|
|
|
from rest_framework.response import Response
|
2023-09-10 15:32:07 +00:00
|
|
|
|
2023-09-12 15:07:47 +00:00
|
|
|
from .models import Word, Grid, Placement, Level
|
|
|
|
|
|
|
|
from .serializers import (
|
|
|
|
WordSerializer,
|
|
|
|
GridSerializer,
|
|
|
|
PlacementSerializer,
|
|
|
|
LevelSerializer,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class LevelViewSet(viewsets.ModelViewSet):
|
|
|
|
queryset = Level.objects.all()
|
|
|
|
serializer_class = LevelSerializer
|
|
|
|
ordering_fields = ["level_number"]
|
|
|
|
|
|
|
|
|
|
|
|
class WordViewSet(viewsets.ModelViewSet):
|
|
|
|
queryset = Word.objects.all()
|
|
|
|
serializer_class = WordSerializer
|
|
|
|
|
|
|
|
|
|
|
|
class GridViewSet(viewsets.ModelViewSet):
|
|
|
|
queryset = Grid.objects.all()
|
|
|
|
serializer_class = GridSerializer
|
|
|
|
|
2023-09-19 15:56:27 +00:00
|
|
|
def partial_update(self, request, pk=None):
|
|
|
|
instance = self.get_object()
|
|
|
|
print(request.data)
|
|
|
|
serializer = self.get_serializer(instance, data=request.data, partial=True)
|
|
|
|
serializer.is_valid(raise_exception=True)
|
|
|
|
self.perform_update(serializer)
|
|
|
|
|
|
|
|
instance.populate()
|
|
|
|
serializer = self.get_serializer(instance)
|
|
|
|
return Response(serializer.data)
|
|
|
|
|
2023-09-12 15:07:47 +00:00
|
|
|
|
|
|
|
class PlacementViewSet(viewsets.ModelViewSet):
|
|
|
|
queryset = Placement.objects.all()
|
|
|
|
serializer_class = PlacementSerializer
|