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):
|
2023-07-11 13:34:35 +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
|
2023-07-11 13:34:35 +00:00
|
|
|
fields = (
|
|
|
|
"uuid",
|
|
|
|
"short_id",
|
|
|
|
"name",
|
|
|
|
"description",
|
|
|
|
"props",
|
|
|
|
"state",
|
|
|
|
"parent",
|
|
|
|
"labels",
|
|
|
|
"owner",
|
|
|
|
"taken_by",
|
|
|
|
"taken_on",
|
|
|
|
"taken_until",
|
|
|
|
"categories",
|
|
|
|
)
|
|
|
|
|
2017-04-28 12:14:27 +00:00
|
|
|
|
|
|
|
class LabelSerializer(serializers.ModelSerializer):
|
2017-10-02 19:20:02 +00:00
|
|
|
item = ItemSerializer(required=False)
|
2023-07-11 13:34:35 +00:00
|
|
|
item_id = serializers.PrimaryKeyRelatedField(queryset=Item.objects, source="item")
|
|
|
|
|
2017-04-28 12:14:27 +00:00
|
|
|
class Meta:
|
|
|
|
model = Label
|
2023-07-11 13:34:35 +00:00
|
|
|
fields = ("id", "item", "item_id", "style")
|