spejstore-new/storage/serializers.py

21 lines
977 B
Python
Raw Normal View History

2020-05-20 21:07:21 +00:00
from django.contrib.auth.models import User
from storage.models import Item, Label, Category
2017-03-06 15:50:55 +00:00
from rest_framework import serializers
from rest_framework_hstore.serializers import HStoreSerializer
class ItemSerializer(HStoreSerializer):
2020-05-20 21:07:21 +00:00
categories = serializers.SlugRelatedField(queryset=Category.objects, many=True, slug_field='name')
owner = serializers.SlugRelatedField(queryset=User.objects, slug_field='username')
taken_by = serializers.SlugRelatedField(queryset=User.objects, slug_field='username')
2017-03-06 15:50:55 +00:00
class Meta:
model = Item
2020-05-20 21:07:21 +00:00
fields = ('uuid', 'short_id', 'name', 'description', 'props', 'state', 'parent', 'owner', 'taken_by', 'taken_on', 'taken_until', 'categories')
2017-04-28 12:14:27 +00:00
class LabelSerializer(serializers.ModelSerializer):
item = ItemSerializer(required=False)
2017-09-05 23:23:04 +00:00
item_id = serializers.PrimaryKeyRelatedField(queryset=Item.objects, source='item')
2017-04-28 12:14:27 +00:00
class Meta:
model = Label
2017-09-05 23:23:04 +00:00
fields = ('id', 'item', 'item_id', 'style')