-
django create-review by FBVProject using python/Cloning Airbnb 2021. 3. 18. 04:58
url 설정
config/urls.py
urlpatterns = [ path("reviews/", include("reviews.urls", namespace="reviews")) ]
reviews/urls.py
from django.urls import path from reviews import views app_name = "reviews" urlpatterns = [ path("<int:reservation_pk>/create/", views.createReview, name="create") ]
FBV(Function Based View)
reviews/views.py
# reviews/views.py from django.shortcuts import redirect, reverse from django.contrib import messages from . import models as review_models from reservations import models as reservation_models def createReview(request, reservation_pk): if request.method == "POST": review = request.POST.get("review") accuracy = int(request.POST.get("accuracy")) communication = int(request.POST.get("communication")) cleanliness = int(request.POST.get("cleanliness")) location = int(request.POST.get("location")) check_in = int(request.POST.get("check_in")) value = int(request.POST.get("value")) reservation = reservation_models.Reservation.objects.get_or_none( pk=reservation_pk ) if reservation is None: messages.error(request, "Reservation does not exist") return redirect( reverse("reservations:detail", kwargs={"pk": reservation_pk}) ) room = reservation.room review = review_models.Review.objects.create( review=review, accuracy=accuracy, communication=communication, cleanliness=cleanliness, location=location, check_in=check_in, value=value, user=request.user, room=room, ) return redirect(reverse("reservations:detail", kwargs={"pk": reservation.pk}))
참고 자료
- 노마드 코더의 Airbnb 클론 강의
소스 코드
github.com/zpskek/airbnb-clone-v3/commit/3e416d1dceaa58afe9e70d7e86eb7f597d311a20
'Project using python > Cloning Airbnb' 카테고리의 다른 글
django delete-review by FBV with axios (0) 2021.03.18 django update-review with axios (0) 2021.03.18 django cancel reservation by FBV (0) 2021.03.17 django confirm reservation by FBV (0) 2021.03.17 django reservation-list on room in host by CBV with ListView (0) 2021.03.17