Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified airlines/db.sqlite3
Binary file not shown.
Binary file modified airlines/flights/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file modified airlines/flights/__pycache__/settings.cpython-37.pyc
Binary file not shown.
Binary file modified airlines/flights/__pycache__/urls.cpython-37.pyc
Binary file not shown.
Binary file modified airlines/flights/__pycache__/wsgi.cpython-37.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion airlines/flights/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
Expand Down
21 changes: 4 additions & 17 deletions airlines/flights/urls.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
"""flights URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""

from django.contrib import admin
from django.urls import path

from travel.views import SearchResultView , HomePageView
from travel import views

urlpatterns = [
path('admin/', admin.site.urls),
path('', HomePageView.as_view(), name="home"),
path('search/', SearchResultView.as_view(), name='search_results'),

]
Binary file modified airlines/travel/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file modified airlines/travel/__pycache__/admin.cpython-37.pyc
Binary file not shown.
Binary file added airlines/travel/__pycache__/forms.cpython-37.pyc
Binary file not shown.
Binary file modified airlines/travel/__pycache__/models.cpython-37.pyc
Binary file not shown.
Binary file added airlines/travel/__pycache__/views.cpython-37.pyc
Binary file not shown.
19 changes: 19 additions & 0 deletions airlines/travel/migrations/0006_auto_20200202_1142.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 2.2.9 on 2020-02-02 10:42

from django.db import migrations, models
import travel.models


class Migration(migrations.Migration):

dependencies = [
('travel', '0005_auto_20200201_1954'),
]

operations = [
migrations.AlterField(
model_name='flight',
name='from_time',
field=models.DateField(validators=[travel.models.present_or_future_date]),
),
]
19 changes: 19 additions & 0 deletions airlines/travel/migrations/0007_auto_20200202_1323.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 2.2.9 on 2020-02-02 12:23

from django.db import migrations, models
import travel.models


class Migration(migrations.Migration):

dependencies = [
('travel', '0006_auto_20200202_1142'),
]

operations = [
migrations.AlterField(
model_name='flight',
name='from_time',
field=models.DateTimeField(validators=[travel.models.present_or_future_date]),
),
]
18 changes: 18 additions & 0 deletions airlines/travel/migrations/0008_auto_20200202_1620.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.9 on 2020-02-02 15:20

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('travel', '0007_auto_20200202_1323'),
]

operations = [
migrations.AlterField(
model_name='flight',
name='from_time',
field=models.TimeField(),
),
]
19 changes: 19 additions & 0 deletions airlines/travel/migrations/0009_auto_20200202_1622.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 2.2.9 on 2020-02-02 15:22

from django.db import migrations, models
import travel.models


class Migration(migrations.Migration):

dependencies = [
('travel', '0008_auto_20200202_1620'),
]

operations = [
migrations.AlterField(
model_name='flight',
name='from_time',
field=models.DateTimeField(validators=[travel.models.present_or_future_date]),
),
]
Binary file modified airlines/travel/migrations/__pycache__/0001_initial.cpython-37.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified airlines/travel/migrations/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
39 changes: 22 additions & 17 deletions airlines/travel/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,55 @@


class Plane(models.Model):
name = models.CharField(max_length=50,unique=True)
num_of_seats = models.IntegerField()
available = models.BooleanField(default=True)
name = models.CharField(max_length=50,unique=True)
num_of_seats = models.IntegerField()
available = models.BooleanField(default=True)

def __str__(self):
return self.name


def present_or_future_date(value):
if value < timezone.now():
raise ValidationError("The date cannot be in the past!")
return value


class Flight(models.Model):
plane_name = models.ForeignKey(Plane,on_delete=models.CASCADE)
from_city = models.CharField(max_length=50)
to_city = models.CharField(max_length=50)
from_time = models.DateTimeField(validators=[present_or_future_date])
to_time = models.TimeField()
plane_name = models.ForeignKey(Plane,on_delete=models.CASCADE)
from_city = models.CharField(max_length=50)
to_city = models.CharField(max_length=50)
from_time = models.DateTimeField(validators=[present_or_future_date])
to_time = models.TimeField()


def __str__(self):
return '{} - {}'.format(self.from_city,self.to_city)




class Passenger(models.Model):
full_name = models.CharField(max_length=100)
age = models.IntegerField()
full_name = models.CharField(max_length=100)
age = models.IntegerField()
GENDER_CHOICES = [('M','Male'),('F','Female')]
gender = models.CharField(choices=GENDER_CHOICES,max_length=1)
gender = models.CharField(choices=GENDER_CHOICES,max_length=1)


def __str__(self):
return self.full_name

class Ticket(models.Model):
passenger = models.ForeignKey(Passenger,on_delete=models.CASCADE)
flight = models.ForeignKey(Flight,on_delete=models.CASCADE)
passenger = models.ForeignKey(Passenger,on_delete=models.CASCADE)
flight = models.ForeignKey(Flight,on_delete=models.CASCADE)


def __str__(self):
return '{} --> ({})'.format(self.passenger,self.flight)


class User_Info(models.Model):
name = models.CharField(max_length=50)
email = models.EmailField()
name = models.CharField(max_length=50)
email = models.EmailField()


def __str__(self):
return self.name
11 changes: 11 additions & 0 deletions airlines/travel/templates/travel/flight_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<h1>flight detail</h1>
<br>
<div>
<ul>
{% for flight in object_list %}

<li>{{ flight.from_city }} - {{ flight.to_city }}</li>

{% endfor %}
</ul>
</div>
18 changes: 18 additions & 0 deletions airlines/travel/templates/travel/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

<h1>HomePage</h1>
<form action="{% url 'search_results' %}" method="get">

<label for="from_city">From City</label>

<input name="departure" type="text" id="from_city">

<label for="to_city">To City</label>

<input name="arrival" type="text" id="to_city">

<label for="from_time">From Date</label>

<input name="departure_date" type="date" id="from_time" required>

<input type="submit" value="search">
</form>
45 changes: 44 additions & 1 deletion airlines/travel/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,46 @@
from django.shortcuts import render
from .models import Plane, Flight, Passenger, Ticket, User_Info
from django.views.generic import TemplateView, ListView
from django.db.models import Q


class HomePageView(TemplateView):
template_name = 'travel/home.html'

class SearchResultView(ListView):
model = Flight
template_name = 'travel/flight_list.html'

def get_queryset(self):
departure = self.request.GET.get('departure')
arrival = self.request.GET.get('arrival')
departure_date = self.request.GET.get('departure_date')
object_list = Flight.objects.filter(
Q(from_city__exact=departure)
& Q(to_city__exact=arrival)
& Q(from_time__contains=departure_date)
)
return object_list












# if request.method == 'POST':
# filled_form = FlightForm(request.POST)
# if filled_form.is_valid():
# context = {'flight_form':filled_form}
# return render(request, 'travel/fligh_list.html',context)
# else:

# flight_form = FlightForm()
# return render(request, 'travel/home.html', {'flight_form':flight_form})


# Create your views here.