From 5b248f970fad9ab8fbc314ab6339623ec4e0935d Mon Sep 17 00:00:00 2001 From: Shim Kyumin Date: Wed, 14 Aug 2024 14:33:09 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EA=B8=B0=EB=B3=B8=20=EC=9D=B4=EB=AF=B8?= =?UTF-8?q?=EC=A7=80=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- friends/serializers.py | 3 ++- restaurants/serializers.py | 12 +++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/friends/serializers.py b/friends/serializers.py index b4ce31f..ce14648 100644 --- a/friends/serializers.py +++ b/friends/serializers.py @@ -138,7 +138,8 @@ def get_image_url(self, obj): 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 + else: + return "https://mugou.s3.ap-southeast-2.amazonaws.com/images/default_profile_img.jpg" class RestaurantSerializer(serializers.ModelSerializer): diff --git a/restaurants/serializers.py b/restaurants/serializers.py index 4ca8ca4..c9caedd 100644 --- a/restaurants/serializers.py +++ b/restaurants/serializers.py @@ -62,7 +62,8 @@ def get_image_url(self, obj): 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 + else: + return "https://mugou.s3.ap-southeast-2.amazonaws.com/images/default_profile_img.jpg" class UserRestaurantListSerializer(serializers.ModelSerializer): @@ -76,6 +77,7 @@ class Meta: class RestaurantDetailSerializer(serializers.ModelSerializer): reviews = serializers.SerializerMethodField() rating_average = serializers.SerializerMethodField() + image_url = serializers.SerializerMethodField() class Meta: model = Restaurant @@ -88,3 +90,11 @@ def get_reviews(self, obj): def get_rating_average(self, obj): return str(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}" + else: + return "https://mugou.s3.ap-southeast-2.amazonaws.com/images/default_profile_img.jpg"