Commit 104213bb authored by Luko van der Maas's avatar Luko van der Maas Committed by Sébastiaan Versteeg
Browse files

Merge branch 'fix/pizza-api' into 'master'

Fix pizza api serializers and viewsets

See merge request !1278

(cherry picked from commit a8e7167f)

ca6bba41 Fix pizza api serializers and viewsets
parent 17972e45
...@@ -37,7 +37,8 @@ class OrderSerializer(serializers.ModelSerializer): ...@@ -37,7 +37,8 @@ class OrderSerializer(serializers.ModelSerializer):
read_only_fields = ('pk', 'payment', 'name', 'member') read_only_fields = ('pk', 'payment', 'name', 'member')
payment = PaymentTypeField(source='payment.type', payment = PaymentTypeField(source='payment.type',
choices=Payment.PAYMENT_TYPE) choices=Payment.PAYMENT_TYPE,
read_only=True)
class AdminOrderSerializer(serializers.ModelSerializer): class AdminOrderSerializer(serializers.ModelSerializer):
...@@ -64,5 +65,6 @@ class AdminOrderSerializer(serializers.ModelSerializer): ...@@ -64,5 +65,6 @@ class AdminOrderSerializer(serializers.ModelSerializer):
).get('type', instance.payment.type) != instance.payment.type: ).get('type', instance.payment.type) != instance.payment.type:
instance.payment.type = validated_data['payment']['type'] instance.payment.type = validated_data['payment']['type']
instance.payment.save() instance.payment.save()
if 'payment' in validated_data:
del validated_data['payment'] del validated_data['payment']
return super().update(instance, validated_data) return super().update(instance, validated_data)
...@@ -8,6 +8,7 @@ from rest_framework.mixins import ListModelMixin ...@@ -8,6 +8,7 @@ from rest_framework.mixins import ListModelMixin
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.viewsets import GenericViewSet, ModelViewSet from rest_framework.viewsets import GenericViewSet, ModelViewSet
from payments.models import Payment
from pizzas.api import serializers from pizzas.api import serializers
from pizzas.models import Product, PizzaEvent, Order from pizzas.models import Product, PizzaEvent, Order
from pizzas.services import can_change_order from pizzas.services import can_change_order
...@@ -54,7 +55,7 @@ class OrderViewset(ModelViewSet): ...@@ -54,7 +55,7 @@ class OrderViewset(ModelViewSet):
return Order.objects.none() return Order.objects.none()
return Order.objects.filter(member=self.request.member, return Order.objects.filter(member=self.request.member,
paid=False, payment__type=Payment.NONE,
pizza_event=event) pizza_event=event)
return Order.objects.filter(member=self.request.member, return Order.objects.filter(member=self.request.member,
pizza_event=event) pizza_event=event)
......
Markdown is supported
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