From 98db9ef76d0f239deefc543be72565ae2a25c2d4 Mon Sep 17 00:00:00 2001 From: Aroy-Art Date: Thu, 20 Feb 2025 22:21:32 +0100 Subject: [PATCH] Fix: description count for empty string descriptions --- backend/api/posts/serializers.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/backend/api/posts/serializers.py b/backend/api/posts/serializers.py index 7052660..87c4935 100644 --- a/backend/api/posts/serializers.py +++ b/backend/api/posts/serializers.py @@ -105,9 +105,15 @@ class PostSerializer(serializers.ModelSerializer): } def get_description(self, obj) -> Dict[str, str]: + desc = obj.description.first().content + if desc == "": + count = 0 + else: + count = obj.description.count() + return { - "count": obj.description.count(), - "content": obj.description.first().content, + "count": count, + "content": desc, } def get_creator(self, obj) -> Dict[str, str]: