Skip to content

Commit

Permalink
media-library-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DevilsAutumn committed Nov 17, 2024
1 parent 0e8f11a commit 92f81c3
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion backend/djangoindia/api/serializers/media_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]:
Expand Down

0 comments on commit 92f81c3

Please sign in to comment.