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 ...@@ -17,6 +17,6 @@ from django.contrib import admin
from django.urls import include, path from django.urls import include, path
urlpatterns = [ urlpatterns = [
path('booking/', include("booking.urls")), path('booking/', include("booking.urls", namespace="booking")),
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
] ]
...@@ -6,9 +6,11 @@ ...@@ -6,9 +6,11 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE-edge"> <meta http-equiv="X-UA-Compatible" content="IE-edge">
<meta name ="viewport" content="width-device width, initial scale=1.0"> <meta name ="viewport" content="width-device width, initial scale=1.0">
<title>Assignments</title> <title>Magis Air Booking</title>
</head> </head>
<body> <body>
<h1> Magis Air </h1>
{% block content %} {% block content %}
{% endblock %} {% endblock %}
......
...@@ -5,16 +5,30 @@ ...@@ -5,16 +5,30 @@
<h1> Booking Details </h1> <h1> Booking Details </h1>
<h1> Passenger Information </h1> <h1> Passenger Information </h1>
<p> <p>
Passenger ID: {{booking.passenger.P_ID}} <br> Passenger ID: {{booking.Passenger.P_ID}} <br>
Passenger Name: {{booking.passenger.First_Name}} {{booking.passenger.Middle_Initial}} {{booking.passenger.Last_Name}}<br> Passenger Name: {{booking.Passenger.First_Name}} {{booking.Passenger.Middle_Initial}} {{booking.Passenger.Last_Name}}<br>
{{booking.passenger.P_ID}} Birth Date: {{booking.Passenger.Birthdate}} <br>
Age: {{booking.Passenger.Age}} <br>
Gender: {{booking.Passenger.Gender}} <br>
</p> </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 %} {% endblock %}
\ No newline at end of file
...@@ -2,11 +2,22 @@ ...@@ -2,11 +2,22 @@
{% block content %} {% block content %}
<h1> Travel History </h1> <h1> Travel History </h1>
<form>
<input type="text" name="q" value="Passenger ID">
<input type="submit">
</form>
<p> <p>
All Bookings: <br>
{% for booking in bookings_list %} {% for s in booking %}
<ul> <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> </ul>
{% endfor %} {% endfor %}
......
from django.urls import path from django.urls import path
from . import views from . import views
from .views import TravelHistoryView #from .views import TravelHistoryView
urlpatterns = [ urlpatterns = [
path("", TravelHistoryView.as_view(), name="index"), #booking/
path("", views.index, name="index"), #index (home page)
#booking/1/details #booking/1/details
path("<int:booking_id>/details/", views.detail, name="detail"), path("<int:booking_id>/details/", views.detail, name="detail"),
] ]
app_name = "assignments"
\ No newline at end of file
from django.http import HttpResponse from django.http import HttpResponse
from django.http import Http404 from django.http import Http404
from django.shortcuts import render, redirect 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.views import View
from django.db.models import F
# Create your views here. # Create your views here.
class TravelHistoryView(View): def index(request):
query_dict = request.GET
def get(self, request): query = query_dict.get("q")
bookings_list = Booking.objects.order_by("Booking_Date") 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 = { context = {
'bookings_list': bookings_list "booking": booking
} }
return render(request, 'booking/index.html', context) return render(request, 'booking/index.html', context)
def detail(request, booking_id=None): def detail(request, booking_id=None):
try: try:
#for other things
booking = Booking.objects.get(pk=booking_id) 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: except Booking.DoesNotExist:
raise Http404("Booking does not exist!") raise Http404("Booking does not exist!")
return render(request, "booking/detail.html", {"booking": booking}) return render(request, "booking/detail.html", context=context)
\ 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