test: test if detail view is working with new url routing

parent 36c1cd6e
{% extends "booking/base.html" %}
{% load static %}
{% block content %}
<h1> Booking Details </h1>
<h1> Passenger Information </h1>
<p>
Passenger ID: {{booking.passenger.P_ID}} <br>
Passenger Name: {{booking.passenger.First_Name}} {{booking.passenger.Middle_Initial}} {{booking.passenger.Last_Name}}<br>
{{booking.passenger.P_ID}}
</p>
{% endblock %}
\ No newline at end of file
...@@ -4,7 +4,7 @@ from .views import TravelHistoryView ...@@ -4,7 +4,7 @@ from .views import TravelHistoryView
urlpatterns = [ urlpatterns = [
path("", TravelHistoryView.as_view(), name="index"), path("", TravelHistoryView.as_view(), name="index"),
#booking/1 #booking/1/details
path("<int:Booking_ID>/", views.detail, name="detail"), path("<int:booking_id>/details/", views.detail, name="detail"),
] ]
\ No newline at end of file
from django.http import HttpResponse from django.http import HttpResponse
from django.http import Http404
from django.shortcuts import render, redirect from django.shortcuts import render, redirect
from .models import Booking from .models import Booking, Passenger
from django.views import View from django.views import View
# Create your views here. # Create your views here.
...@@ -15,6 +16,10 @@ class TravelHistoryView(View): ...@@ -15,6 +16,10 @@ class TravelHistoryView(View):
return render(request, 'booking/index.html', context) return render(request, 'booking/index.html', context)
def detail(request, Booking_ID): def detail(request, booking_id=None):
response = "This is Booking # %s. This will show exact booking details of passenger" try:
return HttpResponse(response %Booking_ID) booking = Booking.objects.get(pk=booking_id)
\ No newline at end of file except Booking.DoesNotExist:
raise Http404("Booking does not exist!")
return render(request, "booking/detail.html", {"booking": booking})
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment