summaryrefslogtreecommitdiffstats
path: root/storage/serializers.py
blob: f554c8fbec0596a80bd3bb082a98d7def846529e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from storage.models import Item, Label, LabelStyle
from rest_framework import serializers
from rest_framework_hstore.serializers import HStoreSerializer


class ItemSerializer(HStoreSerializer):
    class Meta:
        model = Item
        fields = ('uuid', 'name', 'description', 'props', 'state', 'parent')


class LabelStyleSerializer(serializers.ModelSerializer):
    class Meta:
        model = LabelStyle
        fields = ('uuid', 'description', 'length', 'width')


class LabelSerializer(serializers.ModelSerializer):
    item = ItemSerializer(required=False)
    item_id = serializers.PrimaryKeyRelatedField(queryset=Item.objects, source='item')
    style = LabelStyleSerializer(required=True)
    class Meta:
        model = Label
        fields = ('id', 'item', 'item_id', 'style')