add StorageLocation model
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
0d394d531b
commit
93335b2776
8 changed files with 179 additions and 8 deletions
|
|
@ -3,7 +3,7 @@ from authentication.models import KnownIdentity, ToolshedUser, FriendRequestInco
|
|||
from authentication.serializers import OwnerSerializer
|
||||
from files.models import File
|
||||
from files.serializers import FileSerializer
|
||||
from toolshed.models import Category, Property, ItemProperty, InventoryItem, Tag
|
||||
from toolshed.models import Category, Property, ItemProperty, InventoryItem, Tag, StorageLocation
|
||||
|
||||
|
||||
class FriendSerializer(serializers.ModelSerializer):
|
||||
|
|
@ -11,7 +11,7 @@ class FriendSerializer(serializers.ModelSerializer):
|
|||
|
||||
class Meta:
|
||||
model = KnownIdentity
|
||||
fields = ['username', 'public_key']
|
||||
fields = ['id', 'username', 'public_key']
|
||||
|
||||
def get_username(self, obj):
|
||||
return obj.username + '@' + obj.domain
|
||||
|
|
@ -48,6 +48,23 @@ class CategorySerializer(serializers.ModelSerializer):
|
|||
return Category.objects.get(name=data.split("/")[-1])
|
||||
|
||||
|
||||
class StorageLocationSerializer(serializers.ModelSerializer):
|
||||
owner = OwnerSerializer(read_only=True)
|
||||
category = CategorySerializer(required=False, allow_null=True)
|
||||
path = serializers.SerializerMethodField()
|
||||
|
||||
class Meta:
|
||||
model = StorageLocation
|
||||
fields = ['id', 'name', 'description', 'path', 'category', 'owner']
|
||||
read_only_fields = ['path']
|
||||
|
||||
@staticmethod
|
||||
def get_path(obj):
|
||||
if obj.parent:
|
||||
return StorageLocationSerializer.get_path(obj.parent) + "/" + obj.name
|
||||
return obj.name
|
||||
|
||||
|
||||
class ItemPropertySerializer(serializers.ModelSerializer):
|
||||
property = PropertySerializer(read_only=True)
|
||||
|
||||
|
|
@ -74,7 +91,7 @@ class InventoryItemSerializer(serializers.ModelSerializer):
|
|||
class Meta:
|
||||
model = InventoryItem
|
||||
fields = ['id', 'name', 'description', 'owner', 'category', 'availability_policy', 'owned_quantity', 'owner',
|
||||
'tags', 'properties', 'files']
|
||||
'tags', 'properties', 'files', 'storage_location']
|
||||
|
||||
def to_internal_value(self, data):
|
||||
files = data.pop('files', [])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue