diff --git a/backend/djangoindia/api/serializers/media_library.py b/backend/djangoindia/api/serializers/media_library.py index ba54bef7..fb807d68 100644 --- a/backend/djangoindia/api/serializers/media_library.py +++ b/backend/djangoindia/api/serializers/media_library.py @@ -10,16 +10,25 @@ class Meta: class FolderLiteSerializer(serializers.ModelSerializer): children = serializers.SerializerMethodField() + type = serializers.SerializerMethodField() class Meta: model = Folder - fields = ["id", "name", "children"] + fields = ["id", "name", "children", "type"] def get_children(self, obj): return FolderLiteSerializer( obj.children.all(), many=True, context=self.context ).data + def get_type(self, obj): + if len(obj.children.all()) > 0: + return "root" + elif len(obj.children.all()) >= 0 and obj.parent is None: + return "root" + else: + return "children" + def to_representation(self, instance): representation = super().to_representation(instance) if not representation["children"]: