45 lines
1.2 KiB
Python
45 lines
1.2 KiB
Python
from django.shortcuts import render
|
|
from rest_framework import pagination, status, viewsets
|
|
from rest_framework.response import Response
|
|
|
|
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
|
|
|
|
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)
|
|
|
|
|
|
class PlacementViewSet(viewsets.ModelViewSet):
|
|
queryset = Placement.objects.all()
|
|
serializer_class = PlacementSerializer
|