Exemplo n.º 1
0
    def create(self, request):
        event = Event()
        scheduler = Gamer.objects.get(user=request.auth.user)
        game = Game.objects.get(pk=request.data["gameId"])
        event.event_time = request.data["eventTime"]
        event.game = game
        event.scheduler = scheduler
        event.location = ["location"]

        try:
            event.save()
            serializer = EventSerializer(event, context={'request': request})
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        except ValidationError as ex:
            return Response({"reason": ex.message},
                            status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 2
0
    def create(self, request):
        """Handle POST operations for events

        Returns:
            Response -- JSON serialized event instance
        """
        gamer = Gamer.objects.get(user=request.auth.user)

        event = Event()
        event.event_time = request.data["event_time"]
        event.scheduler = gamer

        game = Game.objects.get(pk=request.data["gameId"])
        event.game = game

        try:
            event.save()
            serializer = EventSerializer(event, context={'request': request})
            return Response(serializer.data)
        except ValidationError as ex:
            return Response({"reason": ex.message},
                            status=status.HTTP_400_BAD_REQUEST)