kopia lustrzana https://github.com/HackerspaceKRK/spejstore
improve /api/1/items/:item_id
rodzic
0c883bed2f
commit
a82668ca01
|
@ -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 import serializers
|
||||||
from rest_framework_hstore.serializers import HStoreSerializer
|
from rest_framework_hstore.serializers import HStoreSerializer
|
||||||
|
|
||||||
|
|
||||||
class ItemSerializer(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:
|
class Meta:
|
||||||
model = Item
|
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):
|
class LabelSerializer(serializers.ModelSerializer):
|
||||||
item = ItemSerializer(required=False)
|
item = ItemSerializer(required=False)
|
||||||
|
|
Ładowanie…
Reference in New Issue