2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-15 09:21:26 +00:00

first working example

This commit is contained in:
Matthias
2021-12-06 22:35:14 +01:00
parent de4d057b93
commit 70939a0cf9
6 changed files with 108 additions and 0 deletions

View File

@ -70,6 +70,39 @@ class CategorySerializer(InvenTreeModelSerializer):
]
class CategoryTree(InvenTreeModelSerializer):
""" Serializer for PartCategory """
id = serializers.IntegerField(source='pk', read_only=True)
text = serializers.CharField(source='name', read_only=True)
parent = serializers.SerializerMethodField()
children = serializers.SerializerMethodField()
a_attr = serializers.SerializerMethodField()
def get_parent(self, obj):
return obj.parent.pk if obj.parent else '#'
def get_children(self, obj):
return True if obj.has_children else False
def get_a_attr(self, obj):
return {'href': obj.get_absolute_url()}
class Meta:
model = PartCategory
fields = [
'id',
'text',
'parent',
'children',
'a_attr',
]
class PartAttachmentSerializer(InvenTreeAttachmentSerializer):
"""
Serializer for the PartAttachment class