Commit 0e163631 authored by Gijs Hendriksen's avatar Gijs Hendriksen
Browse files

Separate event detail and order detail

parent 73e79af3
from django.http.response import JsonResponse
from django.shortcuts import get_object_or_404
from django.db import IntegrityError
......@@ -7,7 +6,8 @@ from rest_framework.viewsets import GenericViewSet, ModelViewSet
from rest_framework.mixins import ListModelMixin
from rest_framework.decorators import list_route
from rest_framework.response import Response
from rest_framework.exceptions import ValidationError
from rest_framework.exceptions import (ValidationError, NotFound,
from pizzas.models import Product, PizzaEvent, Order
from pizzas.api import serializers
......@@ -22,30 +22,17 @@ class PizzaViewset(GenericViewSet, ListModelMixin):
if (PizzaEvent.current() or
return super().list(request, *args, **kwargs)
return Response(status=403)
raise PermissionDenied
def event(self, request):
event = PizzaEvent.current()
if event:
order = Order.objects.get(pizza_event=event,
return JsonResponse({
'event': serializers.PizzaEventSerializer(event).data,
'order': serializers.OrderSerializer(order).data
except Order.DoesNotExist:
return JsonResponse({
'event': serializers.PizzaEventSerializer(event).data,
'order': None
serializer = serializers.PizzaEventSerializer(event)
return Response(
return JsonResponse({
'event': None,
'order': None,
raise NotFound
class OrderViewset(ModelViewSet):
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment