From b1409a29eaa54c753c8caacf2501b646fb8ef2a2 Mon Sep 17 00:00:00 2001 From: Shim Kyumin Date: Mon, 12 Aug 2024 16:34:42 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20image=5Furl=EC=9D=84=20S3=20=EA=B8=B0?= =?UTF-8?q?=EB=B0=98=EC=9C=BC=EB=A1=9C=20=EC=A0=9C=EA=B3=B5=ED=95=98?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- friends/serializers.py | 8 ++++++++ restaurants/serializers.py | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/friends/serializers.py b/friends/serializers.py index 8ace04f..fe03628 100644 --- a/friends/serializers.py +++ b/friends/serializers.py @@ -116,6 +116,7 @@ class Meta: class RestaurantlistSerializer(serializers.ModelSerializer): rating_average = serializers.SerializerMethodField() + image_url = serializers.SerializerMethodField() class Meta: model = Restaurant @@ -132,6 +133,13 @@ class Meta: def get_rating_average(self, obj): return obj.rating_average() + def get_image_url(self, obj): + if obj.image_url: # image_url이 null이 아닌 경우에만 처리 + base_url = "https://mugou.s3.ap-southeast-2.amazonaws.com/images/" + image_name = f"{obj.name}.jpg" # 식당 이름을 사용하여 이미지 파일명 생성 + return f"{base_url}{image_name}" + return None + class RestaurantSerializer(serializers.ModelSerializer): # reviews = serializers.SerializerMethodField() diff --git a/restaurants/serializers.py b/restaurants/serializers.py index 6dd430d..640b413 100644 --- a/restaurants/serializers.py +++ b/restaurants/serializers.py @@ -40,6 +40,7 @@ class Meta: class RestaurantlistSerializer(serializers.ModelSerializer): rating_average = serializers.SerializerMethodField() + image_url = serializers.SerializerMethodField() class Meta: model = Restaurant @@ -56,6 +57,13 @@ class Meta: def get_rating_average(self, obj): return obj.rating_average() + def get_image_url(self, obj): + if obj.image_url: # image_url이 null이 아닌 경우에만 처리 + base_url = "https://mugou.s3.ap-southeast-2.amazonaws.com/images/" + image_name = f"{obj.name}.jpg" # 식당 이름을 사용하여 이미지 파일명 생성 + return f"{base_url}{image_name}" + return None + class UserRestaurantListSerializer(serializers.ModelSerializer): restaurant = RestaurantlistSerializer()