From a82668ca010c6fa071b36112a3564a7ee9589336 Mon Sep 17 00:00:00 2001 From: radex Date: Wed, 20 May 2020 23:07:21 +0200 Subject: [PATCH] improve /api/1/items/:item_id --- storage/serializers.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/storage/serializers.py b/storage/serializers.py index f7f58a8..d90e960 100644 --- a/storage/serializers.py +++ b/storage/serializers.py @@ -1,12 +1,16 @@ -from storage.models import Item, Label +from django.contrib.auth.models import User +from storage.models import Item, Label, Category from rest_framework import serializers from rest_framework_hstore.serializers import HStoreSerializer class ItemSerializer(HStoreSerializer): + 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') class Meta: model = Item - fields = ('uuid', 'name', 'description', 'props', 'state', 'parent') + fields = ('uuid', 'short_id', 'name', 'description', 'props', 'state', 'parent', 'owner', 'taken_by', 'taken_on', 'taken_until', 'categories') class LabelSerializer(serializers.ModelSerializer): item = ItemSerializer(required=False)