Skip to content

Commit

Permalink
chore: json response 세팅
Browse files Browse the repository at this point in the history
  • Loading branch information
권아림 committed Jul 26, 2024
1 parent 4c2a6cc commit a0682ca
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 2 deletions.
8 changes: 8 additions & 0 deletions friends/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from rest_framework import serializers
from .models import Friend


class FriendSerializer(serializers.ModelSerializer):
class Meta:
model = Friend
fields = "__all__"
3 changes: 2 additions & 1 deletion mustgou/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.urls import path, include

urlpatterns = [
path("admin/", admin.site.urls),
path("restaurants/", include("restaurants.urls")),
]
8 changes: 8 additions & 0 deletions restaurants/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from rest_framework import serializers
from .models import Restaurant


class RestaurantSerializer(serializers.ModelSerializer):
class Meta:
model = Restaurant
fields = "__all__"
8 changes: 8 additions & 0 deletions restaurants/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.urls import path, include
from restaurants import views


urlpatterns = [
path("restaurants/", views.restaurant_list),
path("api-auth/", include("rest_framework.urls", namespace="rest_framework")),
]
12 changes: 11 additions & 1 deletion restaurants/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# from django.shortcuts import render
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
from .models import Restaurant
from .serializers import RestaurantSerializer

# Create your views here.

@csrf_exempt
def restaurant_list(request):
if request.method == "GET":
restaurants = Restaurant.objects.all()
serializer = RestaurantSerializer(restaurants, many=True)
return JsonResponse(serializer.data)
14 changes: 14 additions & 0 deletions reviews/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from rest_framework import serializers
from .models import Review, Recommend


class ReviewSerializer(serializers.ModelSerializer):
class Meta:
model = Review
fields = "__all__"


class RecommendSerializer(serializers.ModelSerializer):
class Meta:
model = Recommend
fields = "__all__"
8 changes: 8 additions & 0 deletions users/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from rest_framework import serializers
from .models import User


class UserSerializer(serializers.ModelSerializer):
class Meta:
model = User
fields = "__all__"

0 comments on commit a0682ca

Please sign in to comment.