diff --git a/backend/api/posts/serializers.py b/backend/api/posts/serializers.py index 9421efd..7052660 100644 --- a/backend/api/posts/serializers.py +++ b/backend/api/posts/serializers.py @@ -58,7 +58,19 @@ class PostPreviewSerializer(serializers.ModelSerializer): } def get_media(self, obj: PostModel) -> List[Dict[str, str]]: - return [{"type": i.mimetype, "src": i.file.url} for i in obj.files.all()] + data = [] + for i in obj.files.all(): + if i.mimetype.startswith("video/"): + f_type = "video" + elif i.mimetype.startswith("image/gif"): + f_type = "gif" + elif i.mimetype.startswith("image/"): + f_type = "image" + else: + f_type = "other" + + data.append({"type": f_type, "mimetype": i.mimetype, "src": i.file.url}) + return data def get_tags(self, obj: PostModel) -> List[str]: return [tag.slug for tag in obj.tags.all()]