-
django confirm reservation by FBVProject using python/Cloning Airbnb 2021. 3. 17. 10:15
url 설정
config/urls.py
urlpatterns = [ path("reservations/", include("reservations.urls", namespace="reservations")) ]
reservations/urls.py
from django.urls import path from reservations import views app_name = "reservations" urlpatterns = [ path("<int:pk>/confirm/", views.confirmReservation, name="confirm") ]
FBV(Function Based View)
reservations/views.py
# reservations/views.py from django.shortcuts import redirect, reverse from django.contrib.auth.decorators import login_required from django.contrib import messages from django.http import Http404 from reservations import models as reservation_models @login_required def confirmReservation(request, pk): reservation = reservation_models.Reservation.objects.get_or_none(pk=pk) if reservation is None: messages.error(request, "Rservation does not exist") return redirect(reverse("core:home")) # Route Protection if reservation.room.host != request.user: raise Http404() reservation.status = reservation_models.Reservation.STATUS_CONFIRMED reservation.save() room = reservation.room user_pk = request.user.pk room_pk = room.pk return redirect( reverse( "reservations:host-room-list", kwargs={ "user_pk": user_pk, "room_pk": room_pk, }, ) )
참고 자료
- 노마드 코더의 Airbnb 클론 강의
소스 코드
github.com/zpskek/airbnb-clone-v3/commit/8b0c3bce70ede785f1993b72eb4ee941cdf31a1f
'Project using python > Cloning Airbnb' 카테고리의 다른 글
django create-review by FBV (0) 2021.03.18 django cancel reservation by FBV (0) 2021.03.17 django reservation-list on room in host by CBV with ListView (0) 2021.03.17 django reservation-list on room in host by FBV (0) 2021.03.17 django reservation-list on host page by FBV (0) 2021.03.17