Commit 3e0db2df authored by John Raymon C Yu's avatar John Raymon C Yu

added table and query options for origin and destination

parent 1640d091
{% extends "booking/base.html" %} {% extends "booking/base.html" %}
{% block content %} {% block content %}
<head>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 80%;
height: 100%;
}
table.center {
margin-left: auto;
margin-right: auto;
}
td, th {
border: 1px solid #eeeeee;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
form {
width: 80%;
margin-left: auto;
margin-right: auto;
}
</style>
</head>
<h1> Travel History </h1> <h1> Travel History </h1>
<form> <form>
<input type="text" name="q" value="Passenger ID"> <input type="text" name="q" empty_value="" value='Passenger ID'>
<input type="submit"> <input type="submit">
<select id="id_field1" name="originAP">
<option value="Any">Any</option>
{% for j in city %}
<option value={{j.Airport_Code}}>{{j.City_Name}}</option>
{% endfor %}
</select>
<select id="id_field2" name="destinationAP">
<option value="Any">Any</option>
{% for k in city %}
<option value={{k.Airport_Code}}>{{k.City_Name}}</option>
{% endfor %}
</select>
</form> </form>
<p> <p>
<table class="center">
{% for s in booking %} <tr>
<ul>
<th style="color:cornflowerblue">DATE</th>
{{s.Booking_ID.Booking_Date}} <th style="color:cornflowerblue">BOOKING ID</th>
<a href="{% url 'booking:detail' booking_id=s.Booking_ID %}"> <th style="color:cornflowerblue">ORIGIN </th>
{{s.Booking_ID}} <th style="color:cornflowerblue">DESTINATION</th>
</a> </tr>
{{s.Sched_Code.Flight_Code.Origin_Airport.City_Name}} {% for s in booking %}
{{s.Sched_Code.Flight_Code.Destination_Airport.City_Name}} <tr>
<th>{{s.Booking_ID.Booking_Date}}</th>
<th><a href="{% url 'booking:detail' booking_id=s.Booking_ID %}">
</ul> {{s.Booking_ID}}
{% endfor %} </a></th>
<th>{{s.Sched_Code.Flight_Code.Origin_Airport.City_Name}}</th>
<th>{{s.Sched_Code.Flight_Code.Destination_Airport.City_Name}}</th>
</tr>
{% endfor %}
</table>
</p> </p>
......
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, Booking_Sched, Passenger from .models import Booking, Booking_Sched, Passenger, City, Flight, Schedule
from django.views import View from django.views import View
from django.db.models import F from django.db.models import F
...@@ -10,13 +10,43 @@ from django.db.models import F ...@@ -10,13 +10,43 @@ from django.db.models import F
def index(request): def index(request):
query_dict = request.GET query_dict = request.GET
query = query_dict.get("q") query = query_dict.get("q")
booking = Booking_Sched.objects.select_related('Sched_Code', 'Booking_ID').all() originquery = query_dict.get("originAP")
destinationquery = query_dict.get("destinationAP")
city = City.objects.order_by('City_Name').all()
#Initialization
passenger = Booking.objects.select_related('Passenger').values_list('Booking_ID')
originQ = Flight.objects.all()
destinationQ = Flight.objects.all()
sched = Schedule.objects.filter(Flight_Code__in=originQ).filter(Flight_Code__in=destinationQ)
booking = Booking_Sched.objects.select_related('Sched_Code', 'Booking_ID').order_by('-Booking_ID__Booking_Date').all()
#If Origin Query is specifically selected: Activate Origin Filter
if originquery != "Any":
originQ = Flight.objects.filter(Origin_Airport=originquery)
#If Destination Query is specifically selected: Activate Origin Filter
if destinationquery != "Any":
destinationQ = Flight.objects.filter(Destination_Airport=destinationquery)
#To Connect city origin and destination to booking
sched = Schedule.objects.filter(Flight_Code__in=originQ).filter(Flight_Code__in=destinationQ)
#If Search bar is Not empty, null, or 0: Activate Passenger ID Filter
if query is not None: if query is not None:
#get all Bookings with passenger same as query if query != "0":
passenger = Booking.objects.select_related('Passenger').filter(Passenger=query).values_list('Booking_ID') if query != "":
booking = Booking_Sched.objects.select_related('Sched_Code', 'Booking_ID').filter(Booking_ID__in=passenger).all() if query != "Passenger ID":
#get all Bookings with passenger same as query
passenger = Booking.objects.select_related('Passenger').filter(Passenger=query).values_list('Booking_ID')
#Search using all filters(If at least query is searched. If not, then the booking won't display without this)
booking = Booking_Sched.objects.select_related('Sched_Code', 'Booking_ID').filter(Booking_ID__in=passenger, Sched_Code__in=sched).order_by('-Booking_ID__Booking_Date').all()
context = { context = {
"booking": booking "booking": booking,
"city": city
} }
return render(request, 'booking/index.html', context) return render(request, 'booking/index.html', context)
......
No preview for this file type
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