Skip to content

Commit

Permalink
fix: 기본 이미지 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
GalaxyDimension committed Aug 14, 2024
1 parent e81980b commit 5b248f9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion friends/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
12 changes: 11 additions & 1 deletion restaurants/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand All @@ -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"

0 comments on commit 5b248f9

Please sign in to comment.