serializers.py 846 Bytes
Newer Older
Gijs Hendriksen's avatar
Gijs Hendriksen committed
1
2
3
4
5
6
7
8
9
10
11
12
from rest_framework import serializers

from pizzas.models import Product, PizzaEvent, Order


class PizzaSerializer(serializers.ModelSerializer):
    class Meta:
        model = Product
        fields = ('pk', 'name', 'description', 'price', 'available')


class PizzaEventSerializer(serializers.ModelSerializer):
13
14
15

    event = serializers.PrimaryKeyRelatedField(read_only=True)

Gijs Hendriksen's avatar
Gijs Hendriksen committed
16
17
    class Meta:
        model = PizzaEvent
18
        fields = ('start', 'end', 'event', 'title')
Gijs Hendriksen's avatar
Gijs Hendriksen committed
19
20
21
22
23
24
25
26
27
28
29
30
31


class OrderSerializer(serializers.ModelSerializer):
    class Meta:
        model = Order
        fields = ('pk', 'paid', 'product', 'name', 'member')
        read_only_fields = ('pk', 'paid', 'name', 'member')


class AdminOrderSerializer(serializers.ModelSerializer):
    class Meta:
        model = Order
        fields = ('pk', 'paid', 'product', 'name', 'member')