spejstore-new/storage/serializers.py

41 lines
1.1 KiB
Python
Raw Permalink 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
2023-07-17 13:46:00 +00:00
class ItemSerializer(serializers.ModelSerializer):
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):
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")