Commit 1ecfbb42 authored by Gijs Hendriksen's avatar Gijs Hendriksen

Add display name to pizza order API

parent 3da9bd6a
......@@ -44,10 +44,17 @@ class OrderSerializer(serializers.ModelSerializer):
class AdminOrderSerializer(serializers.ModelSerializer):
class Meta:
model = Order
fields = ('pk', 'payment', 'product', 'name', 'member')
fields = ('pk', 'payment', 'product', 'name', 'member',
'display_name')
payment = PaymentTypeField(source='payment.type',
choices=Payment.PAYMENT_TYPE)
display_name = serializers.SerializerMethodField('_display_name')
def _display_name(self, instance):
if instance.member:
return instance.member.get_full_name()
return instance.name
def validate(self, attrs):
if attrs.get('member') and attrs.get('name'):
......
......@@ -61,9 +61,8 @@ class OrderViewset(ModelViewSet):
pizza_event=event)
def get_serializer_class(self):
if (self.action.endswith('update') and
can_change_order(self.request.member,
self.get_object().pizza_event)):
event = PizzaEvent.current()
if can_change_order(self.request.member, event):
return serializers.AdminOrderSerializer
return serializers.OrderSerializer
......
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