saving vanilla ch6 work

This commit is contained in:
2022-02-08 14:19:32 -06:00
parent 9e9f49fee5
commit 4f8d7f6575
4 changed files with 82 additions and 1 deletions
+37
View File
@@ -0,0 +1,37 @@
from django.http import HttpResponseServerError
from rest_framework.viewsets import ViewSet
from rest_framework.response import Response
from rest_framework import serializers, status
from levelupapi.models import Game
class GameView(ViewSet):
"""Level up game types view"""
def retrieve(self, request, pk):
"""Handle GET requests for single game type
Returns:
Response -- JSON serialized game type
"""
game = Game.objects.get(pk=pk)
serializer = GameSerializer(game)
return Response(serializer.data)
def list(self, request):
"""Handle GET requests to get all game types
Returns:
Response -- JSON serialized list of game types
"""
game = Game.objects.all()
serializer = GameSerializer(game, many=True)
return Response(serializer.data)
class GameSerializer(serializers.ModelSerializer):
"""JSON serializer for game types
"""
class Meta:
model = Game
fields = ('id', 'title', 'maker', 'number_of_players', 'skill_level', 'game_type_id', 'gamer_id')