feat: Enable searching in homepage/index

Configure view in homepage to have search function by fixing queries.
Added most of needed info in templates to test.
Configure urls in main project and app.
parent c5d81beb
......@@ -17,6 +17,6 @@ from django.contrib import admin
from django.urls import include, path
urlpatterns = [
path('booking/', include("booking.urls")),
path('booking/', include("booking.urls", namespace="booking")),
path('admin/', admin.site.urls),
]
......@@ -6,11 +6,13 @@
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE-edge">
<meta name ="viewport" content="width-device width, initial scale=1.0">
<title>Assignments</title>
<title>Magis Air Booking</title>
</head>
<body>
{% block content %}
<h1> Magis Air </h1>
{% block content %}
{% endblock %}
</body>
</html>
\ No newline at end of file
......@@ -5,16 +5,30 @@
<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}}
Passenger ID: {{booking.Passenger.P_ID}} <br>
Passenger Name: {{booking.Passenger.First_Name}} {{booking.Passenger.Middle_Initial}} {{booking.Passenger.Last_Name}}<br>
Birth Date: {{booking.Passenger.Birthdate}} <br>
Age: {{booking.Passenger.Age}} <br>
Gender: {{booking.Passenger.Gender}} <br>
</p>
<h1> Total Cost </h1>
PHP {{booking.Total_Cost}}
<h1> Booking Information </h1>
Date Booked: {{booking.Booking_Date}}
<h1> Trip Itinerary </h1>
{% for result in booksched %}
{{result.Sched_Code.Flight_Code}}
{{result.Sched_Code.Departure_Time}}
{{result.Sched_Code.Arrival_Time}}
{{result.Sched_Code.Duration}}
{{result.Sched_Code.Flight_Cost}} <br>
{% endfor %}
{% endblock %}
\ No newline at end of file
......@@ -2,11 +2,22 @@
{% block content %}
<h1> Travel History </h1>
<form>
<input type="text" name="q" value="Passenger ID">
<input type="submit">
</form>
<p>
All Bookings: <br>
{% for booking in bookings_list %}
{% for s in booking %}
<ul>
{{s.Booking_ID.Booking_Date}}
<a href="{% url 'booking:detail' booking_id=s.Booking_ID %}">
{{s.Booking_ID}}
</a>
{{s.Sched_Code.Flight_Code.Origin_Airport.City_Name}}
{{s.Sched_Code.Flight_Code.Destination_Airport.City_Name}}
</ul>
{% endfor %}
......
from django.urls import path
from . import views
from .views import TravelHistoryView
#from .views import TravelHistoryView
urlpatterns = [
path("", TravelHistoryView.as_view(), name="index"),
#booking/1/details
#booking/
path("", views.index, name="index"), #index (home page)
#booking/1/details
path("<int:booking_id>/details/", views.detail, name="detail"),
]
\ No newline at end of file
]
app_name = "assignments"
\ No newline at end of file
from django.http import HttpResponse
from django.http import Http404
from django.shortcuts import render, redirect
from .models import Booking, Passenger
from .models import Booking, Booking_Sched, Passenger
from django.views import View
from django.db.models import F
# Create your views here.
class TravelHistoryView(View):
def get(self, request):
bookings_list = Booking.objects.order_by("Booking_Date")
context = {
'bookings_list': bookings_list
}
return render(request, 'booking/index.html', context)
def index(request):
query_dict = request.GET
query = query_dict.get("q")
booking = Booking_Sched.objects.select_related('Sched_Code', 'Booking_ID').all()
if query is not None:
#get all Bookings with passenger same as query
passenger = Booking.objects.select_related('Passenger').filter(Passenger=query).values_list('Booking_ID')
booking = Booking_Sched.objects.select_related('Sched_Code', 'Booking_ID').filter(Booking_ID__in=passenger).all()
context = {
"booking": booking
}
return render(request, 'booking/index.html', context)
def detail(request, booking_id=None):
try:
#for other things
booking = Booking.objects.get(pk=booking_id)
#for trip itinerary table
booksched = Booking_Sched.objects.select_related('Sched_Code').filter(Booking_ID=booking_id).all()
context = {
"booking": booking,
"booksched": booksched
}
except Booking.DoesNotExist:
raise Http404("Booking does not exist!")
return render(request, "booking/detail.html", {"booking": booking})
\ No newline at end of file
return render(request, "booking/detail.html", context=context)
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