├── users
├── __init__.py
├── migrations
│ ├── __init__.py
│ └── __pycache__
│ │ └── __init__.cpython-311.pyc
├── models.py
├── tests.py
├── admin.py
├── __pycache__
│ ├── admin.cpython-311.pyc
│ ├── apps.cpython-311.pyc
│ ├── models.cpython-311.pyc
│ ├── tests.cpython-311.pyc
│ ├── urls.cpython-311.pyc
│ ├── views.cpython-311.pyc
│ └── __init__.cpython-311.pyc
├── apps.py
├── templates
│ └── users
│ │ ├── layout.html
│ │ ├── user.html
│ │ └── login.html
├── urls.py
└── views.py
├── airline
├── __init__.py
├── __pycache__
│ ├── urls.cpython-311.pyc
│ ├── wsgi.cpython-311.pyc
│ ├── __init__.cpython-311.pyc
│ └── settings.cpython-311.pyc
├── asgi.py
├── wsgi.py
├── urls.py
└── settings.py
├── flights
├── __init__.py
├── migrations
│ ├── __init__.py
│ ├── __pycache__
│ │ ├── __init__.cpython-311.pyc
│ │ ├── 0001_initial.cpython-311.pyc
│ │ ├── 0003_passangers.cpython-311.pyc
│ │ ├── 0008_merge_20230613_1651.cpython-311.pyc
│ │ ├── 0004_rename_passangers_passanger.cpython-311.pyc
│ │ ├── 0005_rename_passanger_passangers.cpython-311.pyc
│ │ ├── 0006_rename_passangers_passanger.cpython-311.pyc
│ │ ├── 0007_rename_passanger_passenger.cpython-311.pyc
│ │ ├── 0002_airport_alter_flight_destination_alter_flight_origin.cpython-311.pyc
│ │ ├── 0003_alter_flight_destination_alter_flight_origin_and_more.cpython-311.pyc
│ │ └── 0004_airport_passenger_alter_flight_destination_and_more.cpython-311.pyc
│ ├── 0008_merge_20230613_1651.py
│ ├── 0004_rename_passangers_passanger.py
│ ├── 0005_rename_passanger_passangers.py
│ ├── 0006_rename_passangers_passanger.py
│ ├── 0007_rename_passanger_passenger.py
│ ├── 0001_initial.py
│ ├── 0003_alter_flight_destination_alter_flight_origin_and_more.py
│ ├── 0003_passangers.py
│ ├── 0002_airport_alter_flight_destination_alter_flight_origin.py
│ └── 0004_airport_passenger_alter_flight_destination_and_more.py
├── tests.py
├── __pycache__
│ ├── apps.cpython-311.pyc
│ ├── urls.cpython-311.pyc
│ ├── admin.cpython-311.pyc
│ ├── models.cpython-311.pyc
│ ├── tests.cpython-311.pyc
│ ├── views.cpython-311.pyc
│ └── __init__.cpython-311.pyc
├── apps.py
├── templates
│ └── flights
│ │ ├── layout.html
│ │ ├── index.html
│ │ └── flight.html
├── urls.py
├── admin.py
├── views.py
└── models.py
├── README.md
├── db.sqlite3
├── .idea
├── .gitignore
├── misc.xml
├── vcs.xml
├── inspectionProfiles
│ ├── profiles_settings.xml
│ └── Project_Default.xml
├── modules.xml
└── airline.iml
├── flights.sql
└── manage.py
/users/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/airline/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/flights/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/users/migrations/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/flights/migrations/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # A simple airline application
2 |
--------------------------------------------------------------------------------
/db.sqlite3:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hamadabcn/airline/HEAD/db.sqlite3
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/flights.sql:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hamadabcn/airline/HEAD/flights.sql
--------------------------------------------------------------------------------
/flights/tests.py:
--------------------------------------------------------------------------------
1 | from django.test import TestCase
2 |
3 | # Create your tests here.
4 |
--------------------------------------------------------------------------------
/users/models.py:
--------------------------------------------------------------------------------
1 | from django.db import models
2 |
3 | # Create your models here.
4 |
--------------------------------------------------------------------------------
/users/tests.py:
--------------------------------------------------------------------------------
1 | from django.test import TestCase
2 |
3 | # Create your tests here.
4 |
--------------------------------------------------------------------------------
/users/admin.py:
--------------------------------------------------------------------------------
1 | from django.contrib import admin
2 |
3 | # Register your models here.
4 |
--------------------------------------------------------------------------------
/airline/__pycache__/urls.cpython-311.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hamadabcn/airline/HEAD/airline/__pycache__/urls.cpython-311.pyc
--------------------------------------------------------------------------------
/airline/__pycache__/wsgi.cpython-311.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hamadabcn/airline/HEAD/airline/__pycache__/wsgi.cpython-311.pyc
--------------------------------------------------------------------------------
/flights/__pycache__/apps.cpython-311.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hamadabcn/airline/HEAD/flights/__pycache__/apps.cpython-311.pyc
--------------------------------------------------------------------------------
/flights/__pycache__/urls.cpython-311.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hamadabcn/airline/HEAD/flights/__pycache__/urls.cpython-311.pyc
--------------------------------------------------------------------------------
/users/__pycache__/admin.cpython-311.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hamadabcn/airline/HEAD/users/__pycache__/admin.cpython-311.pyc
--------------------------------------------------------------------------------
/users/__pycache__/apps.cpython-311.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hamadabcn/airline/HEAD/users/__pycache__/apps.cpython-311.pyc
--------------------------------------------------------------------------------
/users/__pycache__/models.cpython-311.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hamadabcn/airline/HEAD/users/__pycache__/models.cpython-311.pyc
--------------------------------------------------------------------------------
/users/__pycache__/tests.cpython-311.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hamadabcn/airline/HEAD/users/__pycache__/tests.cpython-311.pyc
--------------------------------------------------------------------------------
/users/__pycache__/urls.cpython-311.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hamadabcn/airline/HEAD/users/__pycache__/urls.cpython-311.pyc
--------------------------------------------------------------------------------
/users/__pycache__/views.cpython-311.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hamadabcn/airline/HEAD/users/__pycache__/views.cpython-311.pyc
--------------------------------------------------------------------------------
/flights/__pycache__/admin.cpython-311.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hamadabcn/airline/HEAD/flights/__pycache__/admin.cpython-311.pyc
--------------------------------------------------------------------------------
/flights/__pycache__/models.cpython-311.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hamadabcn/airline/HEAD/flights/__pycache__/models.cpython-311.pyc
--------------------------------------------------------------------------------
/flights/__pycache__/tests.cpython-311.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hamadabcn/airline/HEAD/flights/__pycache__/tests.cpython-311.pyc
--------------------------------------------------------------------------------
/flights/__pycache__/views.cpython-311.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hamadabcn/airline/HEAD/flights/__pycache__/views.cpython-311.pyc
--------------------------------------------------------------------------------
/users/__pycache__/__init__.cpython-311.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hamadabcn/airline/HEAD/users/__pycache__/__init__.cpython-311.pyc
--------------------------------------------------------------------------------
/airline/__pycache__/__init__.cpython-311.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hamadabcn/airline/HEAD/airline/__pycache__/__init__.cpython-311.pyc
--------------------------------------------------------------------------------
/airline/__pycache__/settings.cpython-311.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hamadabcn/airline/HEAD/airline/__pycache__/settings.cpython-311.pyc
--------------------------------------------------------------------------------
/flights/__pycache__/__init__.cpython-311.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hamadabcn/airline/HEAD/flights/__pycache__/__init__.cpython-311.pyc
--------------------------------------------------------------------------------
/flights/migrations/__pycache__/__init__.cpython-311.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hamadabcn/airline/HEAD/flights/migrations/__pycache__/__init__.cpython-311.pyc
--------------------------------------------------------------------------------
/users/migrations/__pycache__/__init__.cpython-311.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hamadabcn/airline/HEAD/users/migrations/__pycache__/__init__.cpython-311.pyc
--------------------------------------------------------------------------------
/flights/migrations/__pycache__/0001_initial.cpython-311.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hamadabcn/airline/HEAD/flights/migrations/__pycache__/0001_initial.cpython-311.pyc
--------------------------------------------------------------------------------
/flights/migrations/__pycache__/0003_passangers.cpython-311.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hamadabcn/airline/HEAD/flights/migrations/__pycache__/0003_passangers.cpython-311.pyc
--------------------------------------------------------------------------------
/users/apps.py:
--------------------------------------------------------------------------------
1 | from django.apps import AppConfig
2 |
3 |
4 | class UsersConfig(AppConfig):
5 | default_auto_field = 'django.db.models.BigAutoField'
6 | name = 'users'
7 |
--------------------------------------------------------------------------------
/flights/apps.py:
--------------------------------------------------------------------------------
1 | from django.apps import AppConfig
2 |
3 |
4 | class FlightsConfig(AppConfig):
5 | default_auto_field = 'django.db.models.BigAutoField'
6 | name = 'flights'
7 |
--------------------------------------------------------------------------------
/flights/migrations/__pycache__/0008_merge_20230613_1651.cpython-311.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hamadabcn/airline/HEAD/flights/migrations/__pycache__/0008_merge_20230613_1651.cpython-311.pyc
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/flights/migrations/__pycache__/0004_rename_passangers_passanger.cpython-311.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hamadabcn/airline/HEAD/flights/migrations/__pycache__/0004_rename_passangers_passanger.cpython-311.pyc
--------------------------------------------------------------------------------
/flights/migrations/__pycache__/0005_rename_passanger_passangers.cpython-311.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hamadabcn/airline/HEAD/flights/migrations/__pycache__/0005_rename_passanger_passangers.cpython-311.pyc
--------------------------------------------------------------------------------
/flights/migrations/__pycache__/0006_rename_passangers_passanger.cpython-311.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hamadabcn/airline/HEAD/flights/migrations/__pycache__/0006_rename_passangers_passanger.cpython-311.pyc
--------------------------------------------------------------------------------
/flights/migrations/__pycache__/0007_rename_passanger_passenger.cpython-311.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hamadabcn/airline/HEAD/flights/migrations/__pycache__/0007_rename_passanger_passenger.cpython-311.pyc
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/users/templates/users/layout.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Users
5 |
6 |
7 | {% block body %}
8 | {% endblock %}
9 |
10 |
--------------------------------------------------------------------------------
/flights/templates/flights/layout.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Flights
5 |
6 |
7 | {% block body %}
8 | {% endblock %}
9 |
10 |
--------------------------------------------------------------------------------
/flights/migrations/__pycache__/0002_airport_alter_flight_destination_alter_flight_origin.cpython-311.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hamadabcn/airline/HEAD/flights/migrations/__pycache__/0002_airport_alter_flight_destination_alter_flight_origin.cpython-311.pyc
--------------------------------------------------------------------------------
/flights/migrations/__pycache__/0003_alter_flight_destination_alter_flight_origin_and_more.cpython-311.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hamadabcn/airline/HEAD/flights/migrations/__pycache__/0003_alter_flight_destination_alter_flight_origin_and_more.cpython-311.pyc
--------------------------------------------------------------------------------
/flights/migrations/__pycache__/0004_airport_passenger_alter_flight_destination_and_more.cpython-311.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Hamadabcn/airline/HEAD/flights/migrations/__pycache__/0004_airport_passenger_alter_flight_destination_and_more.cpython-311.pyc
--------------------------------------------------------------------------------
/flights/urls.py:
--------------------------------------------------------------------------------
1 | from django.urls import path
2 | from . import views
3 |
4 | urlpatterns = [
5 | path("", views.index, name="index"),
6 | path("", views.flight, name="flight"),
7 | path("/book", views.book, name="book")
8 | ]
9 |
--------------------------------------------------------------------------------
/users/urls.py:
--------------------------------------------------------------------------------
1 | from django.urls import path
2 |
3 | from . import views
4 |
5 | urlpatterns = [
6 | path("", views.index, name="index"),
7 | path("login", views.login_view, name="login"),
8 | path("logout", views.logout_view, name="logout")
9 | ]
10 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/users/templates/users/user.html:
--------------------------------------------------------------------------------
1 | {% extends "users/layout.html" %}
2 |
3 | {% block body %}
4 |
5 | Welcome{{ request.user.first_name }}
6 |
7 | - Username{{ request.user.username }}
8 | - e-mail: {{ request.user.email }}
9 |
10 |
11 | Log Out
12 | {% endblock %}
--------------------------------------------------------------------------------
/flights/migrations/0008_merge_20230613_1651.py:
--------------------------------------------------------------------------------
1 | # Generated by Django 4.2.1 on 2023-06-13 14:51
2 |
3 | from django.db import migrations
4 |
5 |
6 | class Migration(migrations.Migration):
7 |
8 | dependencies = [
9 | ('flights', '0004_airport_passenger_alter_flight_destination_and_more'),
10 | ('flights', '0007_rename_passanger_passenger'),
11 | ]
12 |
13 | operations = [
14 | ]
15 |
--------------------------------------------------------------------------------
/flights/migrations/0004_rename_passangers_passanger.py:
--------------------------------------------------------------------------------
1 | # Generated by Django 4.2.1 on 2023-06-06 22:25
2 |
3 | from django.db import migrations
4 |
5 |
6 | class Migration(migrations.Migration):
7 |
8 | dependencies = [
9 | ('flights', '0003_passangers'),
10 | ]
11 |
12 | operations = [
13 | migrations.RenameModel(
14 | old_name='Passangers',
15 | new_name='Passanger',
16 | ),
17 | ]
18 |
--------------------------------------------------------------------------------
/flights/templates/flights/index.html:
--------------------------------------------------------------------------------
1 | {% extends "flights/layout.html" %}
2 |
3 | {% block body %}
4 | Flights
5 |
14 | {% endblock %}
--------------------------------------------------------------------------------
/airline/asgi.py:
--------------------------------------------------------------------------------
1 | """
2 | ASGI config for airline project.
3 |
4 | It exposes the ASGI callable as a module-level variable named ``application``.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/
8 | """
9 |
10 | import os
11 |
12 | from django.core.asgi import get_asgi_application
13 |
14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'airline.settings')
15 |
16 | application = get_asgi_application()
17 |
--------------------------------------------------------------------------------
/airline/wsgi.py:
--------------------------------------------------------------------------------
1 | """
2 | WSGI config for airline project.
3 |
4 | It exposes the WSGI callable as a module-level variable named ``application``.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/4.2/howto/deployment/wsgi/
8 | """
9 |
10 | import os
11 |
12 | from django.core.wsgi import get_wsgi_application
13 |
14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'airline.settings')
15 |
16 | application = get_wsgi_application()
17 |
--------------------------------------------------------------------------------
/flights/admin.py:
--------------------------------------------------------------------------------
1 | from django.contrib import admin
2 | from .models import Flight, Airport, Passenger
3 |
4 | # Register your models here.
5 | class FlightAdmin(admin.ModelAdmin):
6 | list_display = ("id", "origin", "destination", "duration")
7 |
8 | class PassengerAdmin(admin.ModelAdmin):
9 | filter_horizontal = ("flights", )
10 |
11 | admin.site.register(Airport)
12 | admin.site.register(Flight, FlightAdmin)
13 | admin.site.register(Passenger, PassengerAdmin)
--------------------------------------------------------------------------------
/flights/migrations/0005_rename_passanger_passangers.py:
--------------------------------------------------------------------------------
1 | # Generated by Django 4.2.1 on 2023-06-06 22:26
2 |
3 | from django.db import migrations
4 |
5 |
6 | class Migration(migrations.Migration):
7 |
8 | dependencies = [
9 | ('flights', '0004_rename_passangers_passanger'),
10 | ]
11 |
12 | operations = [
13 | migrations.RenameModel(
14 | old_name='Passanger',
15 | new_name='Passangers',
16 | ),
17 | ]
18 |
--------------------------------------------------------------------------------
/flights/migrations/0006_rename_passangers_passanger.py:
--------------------------------------------------------------------------------
1 | # Generated by Django 4.2.1 on 2023-06-07 00:41
2 |
3 | from django.db import migrations
4 |
5 |
6 | class Migration(migrations.Migration):
7 |
8 | dependencies = [
9 | ('flights', '0005_rename_passanger_passangers'),
10 | ]
11 |
12 | operations = [
13 | migrations.RenameModel(
14 | old_name='Passangers',
15 | new_name='Passanger',
16 | ),
17 | ]
18 |
--------------------------------------------------------------------------------
/flights/migrations/0007_rename_passanger_passenger.py:
--------------------------------------------------------------------------------
1 | # Generated by Django 4.2.1 on 2023-06-08 18:20
2 |
3 | from django.db import migrations
4 |
5 |
6 | class Migration(migrations.Migration):
7 |
8 | dependencies = [
9 | ('flights', '0006_rename_passangers_passanger'),
10 | ]
11 |
12 | operations = [
13 | migrations.RenameModel(
14 | old_name='Passanger',
15 | new_name='Passenger',
16 | ),
17 | ]
18 |
--------------------------------------------------------------------------------
/users/templates/users/login.html:
--------------------------------------------------------------------------------
1 | {% extends "users/layout.html" %}
2 |
3 | {% block body %}
4 |
5 | {% if message %}
6 | {{ message }}
7 | {% endif %}
8 |
9 |
15 | {% endblock %}
--------------------------------------------------------------------------------
/.idea/airline.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/flights/migrations/0001_initial.py:
--------------------------------------------------------------------------------
1 | # Generated by Django 4.2.1 on 2023-06-06 18:37
2 |
3 | from django.db import migrations, models
4 |
5 |
6 | class Migration(migrations.Migration):
7 |
8 | initial = True
9 |
10 | dependencies = [
11 | ]
12 |
13 | operations = [
14 | migrations.CreateModel(
15 | name='Flight',
16 | fields=[
17 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18 | ('origin', models.CharField(max_length=64)),
19 | ('destination', models.CharField(max_length=64)),
20 | ('duration', models.IntegerField()),
21 | ],
22 | ),
23 | ]
24 |
--------------------------------------------------------------------------------
/manage.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | """Django's command-line utility for administrative tasks."""
3 | import os
4 | import sys
5 |
6 |
7 | def main():
8 | """Run administrative tasks."""
9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'airline.settings')
10 | try:
11 | from django.core.management import execute_from_command_line
12 | except ImportError as exc:
13 | raise ImportError(
14 | "Couldn't import Django. Are you sure it's installed and "
15 | "available on your PYTHONPATH environment variable? Did you "
16 | "forget to activate a virtual environment?"
17 | ) from exc
18 | execute_from_command_line(sys.argv)
19 |
20 |
21 | if __name__ == '__main__':
22 | main()
23 |
--------------------------------------------------------------------------------
/flights/migrations/0003_alter_flight_destination_alter_flight_origin_and_more.py:
--------------------------------------------------------------------------------
1 | # Generated by Django 4.2.1 on 2023-06-06 16:03
2 |
3 | from django.db import migrations, models
4 |
5 |
6 | class Migration(migrations.Migration):
7 |
8 | dependencies = [
9 | ('flights', '0002_airport_alter_flight_destination_alter_flight_origin'),
10 | ]
11 |
12 | operations = [
13 | migrations.AlterField(
14 | model_name='flight',
15 | name='destination',
16 | field=models.CharField(max_length=65),
17 | ),
18 | migrations.AlterField(
19 | model_name='flight',
20 | name='origin',
21 | field=models.CharField(max_length=65),
22 | ),
23 | migrations.DeleteModel(
24 | name='Airport',
25 | ),
26 | ]
27 |
--------------------------------------------------------------------------------
/flights/migrations/0003_passangers.py:
--------------------------------------------------------------------------------
1 | # Generated by Django 4.2.1 on 2023-06-06 22:05
2 |
3 | from django.db import migrations, models
4 |
5 |
6 | class Migration(migrations.Migration):
7 |
8 | dependencies = [
9 | ('flights', '0002_airport_alter_flight_destination_alter_flight_origin'),
10 | ]
11 |
12 | operations = [
13 | migrations.CreateModel(
14 | name='Passangers',
15 | fields=[
16 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
17 | ('first', models.CharField(max_length=64)),
18 | ('last', models.CharField(max_length=64)),
19 | ('flights', models.ManyToManyField(blank=True, related_name='passangers', to='flights.flight')),
20 | ],
21 | ),
22 | ]
23 |
--------------------------------------------------------------------------------
/airline/urls.py:
--------------------------------------------------------------------------------
1 | """
2 | URL configuration for airline project.
3 |
4 | The `urlpatterns` list routes URLs to views. For more information please see:
5 | https://docs.djangoproject.com/en/4.2/topics/http/urls/
6 | Examples:
7 | Function views
8 | 1. Add an import: from my_app import views
9 | 2. Add a URL to urlpatterns: path('', views.home, name='home')
10 | Class-based views
11 | 1. Add an import: from other_app.views import Home
12 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
13 | Including another URLconf
14 | 1. Import the include() function: from django.urls import include, path
15 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
16 | """
17 | from django.contrib import admin
18 | from django.urls import include, path
19 |
20 | urlpatterns = [
21 | path('admin/', admin.site.urls),
22 | path('flights/', include('flights.urls')),
23 | path('users/', include('users.urls'))
24 | ]
25 |
--------------------------------------------------------------------------------
/flights/views.py:
--------------------------------------------------------------------------------
1 | from django.shortcuts import render
2 | from django.http import HttpResponseRedirect
3 | from django.urls import reverse
4 | from .models import Flight, Passenger
5 |
6 | # Create your views here.
7 | def index(request):
8 | return render(request, "flights/index.html", {
9 | "flights": Flight.objects.all()
10 | })
11 |
12 | def flight(request, flight_id):
13 | flight = Flight.objects.get(pk=flight_id)
14 | return render(request, "flights/flight.html", {
15 | "flight": flight,
16 | "passengers": flight.passengers.all(),
17 | "non_passengers": Passenger.objects.exclude(flights=flight).all()
18 | })
19 |
20 | def book(request, flight_id):
21 | if request.method == "POST":
22 | flight = Flight.objects.get(pk=flight_id)
23 | passenger = Passenger.objects.get(pk=int(request.POST["passengers"]))
24 | passenger.flights.add(flight)
25 | return HttpResponseRedirect(reverse("flight", args=(flight.id,)))
--------------------------------------------------------------------------------
/flights/templates/flights/flight.html:
--------------------------------------------------------------------------------
1 | {% extends "flights/layout.html" %}
2 |
3 | {% block body %}
4 | Flight {{ flight.id }}
5 |
6 | - Origin: {{ flight.origin }}
7 | - Destination: {{ flight.destination }}
8 | - Duration: {{ flight.duration }}
9 |
10 |
11 | Passengers
12 |
13 |
14 | {% for passenger in passengers %}
15 | - {{ passenger }}
16 | {% empty %}
17 | - No passengers
18 | {% endfor %}
19 |
20 |
21 | Add Passenger
22 |
23 |
32 |
33 | Back to Flight list
34 |
35 | {% endblock %}
--------------------------------------------------------------------------------
/flights/models.py:
--------------------------------------------------------------------------------
1 | from django.db import models
2 |
3 |
4 | # Create your models here.
5 | class Airport(models.Model):
6 | code = models.CharField(max_length=3)
7 | city = models.CharField(max_length=64)
8 |
9 | def __str__(self):
10 | return f"{self.city} ({self.code})"
11 |
12 | class Flight(models.Model):
13 | origin = models.ForeignKey(Airport, on_delete=models.CASCADE, related_name="departures")
14 | destination = models.ForeignKey(Airport, on_delete=models.CASCADE, related_name="arrivals")
15 | duration = models.IntegerField()
16 |
17 | def __str__(self):
18 | return f"{self.id}: {self.origin} to {self.destination}"
19 |
20 | def is_vaild_flight(self):
21 | return self.origin != self.destination and self.duration > 0
22 |
23 | class Passenger(models.Model):
24 | first = models.CharField(max_length=64)
25 | last = models.CharField(max_length=64)
26 | flights = models.ManyToManyField(Flight, blank=True, related_name="passangers")
27 |
28 | def __str__(self):
29 | return f"{self.first}: {self.last}"
30 |
--------------------------------------------------------------------------------
/users/views.py:
--------------------------------------------------------------------------------
1 | from django.shortcuts import render
2 | from django.shortcuts import HttpResponseRedirect
3 | from django.urls import reverse
4 | from django.contrib.auth import authenticate, login, logout
5 |
6 | # Create your views here.
7 | def index(request):
8 | if not request.user.is_authenticated:
9 | return HttpResponseRedirect(reverse("login"))
10 | return render(request, "users/user.html")
11 |
12 |
13 | def login_view(request):
14 | if request.method == "POST":
15 | username = request.POST["username"]
16 | password = request.POST["password"]
17 | user = authenticate(request, username=username, password=password)
18 | if user is not None:
19 | login(request, user)
20 | return HttpResponseRedirect(reverse("index"))
21 | else:
22 | return render(request, "users/login.html", {
23 | "message": "Invalid username or password"
24 | })
25 |
26 | def logout_view(request):
27 | logout(request)
28 | return render(request, "users/login.html", {
29 | "message": "Logged out."
30 | })
--------------------------------------------------------------------------------
/flights/migrations/0002_airport_alter_flight_destination_alter_flight_origin.py:
--------------------------------------------------------------------------------
1 | # Generated by Django 4.2.1 on 2023-06-06 19:20
2 |
3 | from django.db import migrations, models
4 | import django.db.models.deletion
5 |
6 |
7 | class Migration(migrations.Migration):
8 |
9 | dependencies = [
10 | ('flights', '0001_initial'),
11 | ]
12 |
13 | operations = [
14 | migrations.CreateModel(
15 | name='Airport',
16 | fields=[
17 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18 | ('code', models.CharField(max_length=3)),
19 | ('city', models.CharField(max_length=64)),
20 | ],
21 | ),
22 | migrations.AlterField(
23 | model_name='flight',
24 | name='destination',
25 | field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='arrivals', to='flights.airport'),
26 | ),
27 | migrations.AlterField(
28 | model_name='flight',
29 | name='origin',
30 | field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='departures', to='flights.airport'),
31 | ),
32 | ]
33 |
--------------------------------------------------------------------------------
/flights/migrations/0004_airport_passenger_alter_flight_destination_and_more.py:
--------------------------------------------------------------------------------
1 | # Generated by Django 4.2.1 on 2023-06-13 03:10
2 |
3 | from django.db import migrations, models
4 | import django.db.models.deletion
5 |
6 |
7 | class Migration(migrations.Migration):
8 |
9 | dependencies = [
10 | ('flights', '0003_alter_flight_destination_alter_flight_origin_and_more'),
11 | ]
12 |
13 | operations = [
14 | migrations.CreateModel(
15 | name='Airport',
16 | fields=[
17 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18 | ('code', models.CharField(max_length=3)),
19 | ('city', models.CharField(max_length=64)),
20 | ],
21 | ),
22 | migrations.CreateModel(
23 | name='Passenger',
24 | fields=[
25 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
26 | ('first', models.CharField(max_length=64)),
27 | ('last', models.CharField(max_length=64)),
28 | ('flights', models.ManyToManyField(blank=True, related_name='passangers', to='flights.flight')),
29 | ],
30 | ),
31 | migrations.AlterField(
32 | model_name='flight',
33 | name='destination',
34 | field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='arrivals', to='flights.airport'),
35 | ),
36 | migrations.AlterField(
37 | model_name='flight',
38 | name='origin',
39 | field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='departures', to='flights.airport'),
40 | ),
41 | ]
42 |
--------------------------------------------------------------------------------
/airline/settings.py:
--------------------------------------------------------------------------------
1 | """
2 | Django settings for airline project.
3 |
4 | Generated by 'django-admin startproject' using Django 4.2.1.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/4.2/topics/settings/
8 |
9 | For the full list of settings and their values, see
10 | https://docs.djangoproject.com/en/4.2/ref/settings/
11 | """
12 |
13 | from pathlib import Path
14 |
15 | # Build paths inside the project like this: BASE_DIR / 'subdir'.
16 | BASE_DIR = Path(__file__).resolve().parent.parent
17 |
18 |
19 | # Quick-start development settings - unsuitable for production
20 | # See https://docs.djangoproject.com/en/4.2/howto/deployment/checklist/
21 |
22 | # SECURITY WARNING: keep the secret key used in production secret!
23 | SECRET_KEY = 'django-insecure-=3n3u+cvd)ns(7(bluqjf^_n0k4qpxke!4n2*oumrf(j*q7xjs'
24 |
25 | # SECURITY WARNING: don't run with debug turned on in production!
26 | DEBUG = True
27 |
28 | ALLOWED_HOSTS = []
29 |
30 |
31 | # Application definition
32 |
33 | INSTALLED_APPS = [
34 | 'flights',
35 | 'users',
36 | 'django.contrib.admin',
37 | 'django.contrib.auth',
38 | 'django.contrib.contenttypes',
39 | 'django.contrib.sessions',
40 | 'django.contrib.messages',
41 | 'django.contrib.staticfiles',
42 | ]
43 |
44 | MIDDLEWARE = [
45 | 'django.middleware.security.SecurityMiddleware',
46 | 'django.contrib.sessions.middleware.SessionMiddleware',
47 | 'django.middleware.common.CommonMiddleware',
48 | 'django.middleware.csrf.CsrfViewMiddleware',
49 | 'django.contrib.auth.middleware.AuthenticationMiddleware',
50 | 'django.contrib.messages.middleware.MessageMiddleware',
51 | 'django.middleware.clickjacking.XFrameOptionsMiddleware',
52 | ]
53 |
54 | ROOT_URLCONF = 'airline.urls'
55 |
56 | TEMPLATES = [
57 | {
58 | 'BACKEND': 'django.template.backends.django.DjangoTemplates',
59 | 'DIRS': [],
60 | 'APP_DIRS': True,
61 | 'OPTIONS': {
62 | 'context_processors': [
63 | 'django.template.context_processors.debug',
64 | 'django.template.context_processors.request',
65 | 'django.contrib.auth.context_processors.auth',
66 | 'django.contrib.messages.context_processors.messages',
67 | ],
68 | },
69 | },
70 | ]
71 |
72 | WSGI_APPLICATION = 'airline.wsgi.application'
73 |
74 |
75 | # Database
76 | # https://docs.djangoproject.com/en/4.2/ref/settings/#databases
77 |
78 | DATABASES = {
79 | 'default': {
80 | 'ENGINE': 'django.db.backends.sqlite3',
81 | 'NAME': BASE_DIR / 'db.sqlite3',
82 | }
83 | }
84 |
85 |
86 | # Password validation
87 | # https://docs.djangoproject.com/en/4.2/ref/settings/#auth-password-validators
88 |
89 | AUTH_PASSWORD_VALIDATORS = [
90 | {
91 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
92 | },
93 | {
94 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
95 | },
96 | {
97 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
98 | },
99 | {
100 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
101 | },
102 | ]
103 |
104 |
105 | # Internationalization
106 | # https://docs.djangoproject.com/en/4.2/topics/i18n/
107 |
108 | LANGUAGE_CODE = 'en-us'
109 |
110 | TIME_ZONE = 'UTC'
111 |
112 | USE_I18N = True
113 |
114 | USE_TZ = True
115 |
116 |
117 | # Static files (CSS, JavaScript, Images)
118 | # https://docs.djangoproject.com/en/4.2/howto/static-files/
119 |
120 | STATIC_URL = 'static/'
121 |
122 | # Default primary key field type
123 | # https://docs.djangoproject.com/en/4.2/ref/settings/#default-auto-field
124 |
125 | DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
126 |
--------------------------------------------------------------------------------