Skip to content

Commit

Permalink
feat: 상세정보 리뷰 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
dkfla committed Aug 1, 2024
1 parent 6cbeecb commit 00d4fd3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 35 deletions.
35 changes: 1 addition & 34 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,46 +1,13 @@
asgiref==3.8.1
blinker==1.4
certifi==2024.7.4
charset-normalizer==3.3.2
cryptography==3.4.8
dbus-python==1.2.18
distro==1.7.0
distro-info==1.1+ubuntu0.1
Django==4.2.14
django-cors-headers==4.4.0
django-environ==0.11.2
djangorestframework==3.15.2
gunicorn==22.0.0
httplib2==0.20.2
idna==3.7
importlib-metadata==4.6.4
jeepney==0.7.1
keyring==23.5.0
launchpadlib==1.10.16
lazr.restfulclient==0.14.4
lazr.uri==1.0.6
more-itertools==8.10.0
mysqlclient==2.2.4
netifaces==0.11.0
oauthlib==3.2.0
packaging==24.1
pillow==10.4.0
Pygments==2.11.2
PyGObject==3.42.1
PyJWT==2.3.0
PyMySQL==1.1.1
pyparsing==2.4.7
python-apt==2.4.0+ubuntu3
python-decouple==3.8
PyYAML==5.4.1
requests==2.32.3
SecretStorage==3.3.1
setuptools==70.0.0
six==1.16.0
sqlparse==0.5.0
typing_extensions==4.12.2
ubuntu-advantage-tools==8001
ufw==0.36.1
unattended-upgrades==0.1
urllib3==2.2.2
wadllib==1.3.6
zipp==1.0.0
8 changes: 8 additions & 0 deletions restaurants/serializers.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
from rest_framework import serializers
from .models import Restaurant, SearchHistory, UserRestaurantsList
from reviews.serializers import ReviewSerializer


class RestaurantSerializer(serializers.ModelSerializer):
reviews = serializers.SerializerMethodField()

class Meta:
model = Restaurant
fields = "__all__"

def get_reviews(self, obj):
reviews = obj.reviews.order_by("-recommend_count")[:4]
serializer = ReviewSerializer(reviews, many=True)
return serializer.data


class RestaurantListSerializer(serializers.ModelSerializer):
rating_average = serializers.SerializerMethodField()
Expand Down
2 changes: 1 addition & 1 deletion restaurants/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def add_remove_restaurant(request, pk):
@login_required
def restaurant_detail(request, pk):
try:
restaurant = Restaurant.objects.get(pk=pk)
restaurant = Restaurant.objects.prefetch_related("reviews").get(pk=pk)
serializer = RestaurantSerializer(restaurant)
return Response(serializer.data)
except Restaurant.DoesNotExist:
Expand Down

0 comments on commit 00d4fd3

Please sign in to comment.