Archived
saving vanilla ch6 work
This commit is contained in:
@@ -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 Event
|
||||
|
||||
class EventView(ViewSet):
|
||||
"""Level up event types view"""
|
||||
|
||||
def retrieve(self, request, pk):
|
||||
"""Handle GET requests for single event type
|
||||
|
||||
|
||||
Returns:
|
||||
Response -- JSON serialized event type
|
||||
"""
|
||||
event = Event.objects.get(pk=pk)
|
||||
serializer = EventSerializer(event)
|
||||
return Response(serializer.data)
|
||||
|
||||
|
||||
def list(self, request):
|
||||
"""Handle GET requests to get all event types
|
||||
|
||||
Returns:
|
||||
Response -- JSON serialized list of event types
|
||||
"""
|
||||
event = Event.objects.all()
|
||||
serializer = EventSerializer(event, many=True)
|
||||
return Response(serializer.data)
|
||||
|
||||
class EventSerializer(serializers.ModelSerializer):
|
||||
"""JSON serializer for event types
|
||||
"""
|
||||
class Meta:
|
||||
model = Event
|
||||
fields = ('id', 'description', 'date', 'time', 'game_id', 'organizer_id')
|
||||
Reference in New Issue
Block a user