From 1074d17fb0dc3b05f4ec7dc513faa69ddf962d98 Mon Sep 17 00:00:00 2001 From: Tyrel Souza <923113+tyrelsouza@users.noreply.github.com> Date: Sun, 15 Sep 2019 01:38:18 -0400 Subject: [PATCH] models and stuff --- .gitignore | 195 ++++++++++++++++++++++ README.md | 2 + logbook/flight/__init__.py | 0 logbook/flight/admin.py | 17 ++ logbook/flight/apps.py | 5 + logbook/flight/migrations/0001_initial.py | 56 +++++++ logbook/flight/migrations/__init__.py | 0 logbook/flight/models.py | 46 +++++ logbook/flight/tests.py | 3 + logbook/flight/views.py | 3 + logbook/logbook/settings.py | 11 +- logbook/logbook/urls.py | 4 - readme | 1 - requirements.txt | 13 +- 14 files changed, 343 insertions(+), 13 deletions(-) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 logbook/flight/__init__.py create mode 100644 logbook/flight/admin.py create mode 100644 logbook/flight/apps.py create mode 100644 logbook/flight/migrations/0001_initial.py create mode 100644 logbook/flight/migrations/__init__.py create mode 100644 logbook/flight/models.py create mode 100644 logbook/flight/tests.py create mode 100644 logbook/flight/views.py delete mode 100644 readme diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..48d91c5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,195 @@ + +# Created by https://www.gitignore.io/api/python,django +# Edit at https://www.gitignore.io/?templates=python,django + +### Django ### +*.log +*.pot +*.pyc +__pycache__/ +local_settings.py +db.sqlite3 +media + +# If your build process includes running collectstatic, then you probably don't need or want to include staticfiles/ +# in your Git repository. Update and uncomment the following line accordingly. +# /staticfiles/ + +### Django.Python Stack ### +# Byte-compiled / optimized / DLL files +*.py[cod] +*$py.class + +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo + +# Django stuff: +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock + +# celery beat schedule file +celerybeat-schedule + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ + +### Python ### +# Byte-compiled / optimized / DLL files + +# C extensions + +# Distribution / packaging + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. + +# Installer logs + +# Unit test / coverage reports + +# Translations + +# Django stuff: + +# Flask stuff: + +# Scrapy stuff: + +# Sphinx documentation + +# PyBuilder + +# Jupyter Notebook + +# IPython + +# pyenv + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. + +# celery beat schedule file + +# SageMath parsed files + +# Environments + +# Spyder project settings + +# Rope project settings + +# mkdocs documentation + +# mypy + +# Pyre type checker + +# End of https://www.gitignore.io/api/python,django + diff --git a/README.md b/README.md new file mode 100644 index 0000000..d024e77 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +https://www.pydanny.com/drf-jwt-axios-vue.html +https://medium.com/@williamgnlee/simple-integrated-django-vue-js-web-application-configured-for-heroku-deployment-c4bd2b37aa70 diff --git a/logbook/flight/__init__.py b/logbook/flight/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/logbook/flight/admin.py b/logbook/flight/admin.py new file mode 100644 index 0000000..cd34fa6 --- /dev/null +++ b/logbook/flight/admin.py @@ -0,0 +1,17 @@ +from django.contrib import admin + +from flight.models import Flight, Plane, Airport +# Register your models here. + + +class FlightAdmin(admin.ModelAdmin): + pass +admin.site.register(Flight, FlightAdmin) + +class PlaneAdmin(admin.ModelAdmin): + pass +admin.site.register(Plane, PlaneAdmin) + +class AirportAdmin(admin.ModelAdmin): + pass +admin.site.register(Airport, AirportAdmin) \ No newline at end of file diff --git a/logbook/flight/apps.py b/logbook/flight/apps.py new file mode 100644 index 0000000..9a4a09f --- /dev/null +++ b/logbook/flight/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class FlightConfig(AppConfig): + name = 'flight' diff --git a/logbook/flight/migrations/0001_initial.py b/logbook/flight/migrations/0001_initial.py new file mode 100644 index 0000000..73b6b8a --- /dev/null +++ b/logbook/flight/migrations/0001_initial.py @@ -0,0 +1,56 @@ +# Generated by Django 2.2.5 on 2019-09-15 05:25 + +from decimal import Decimal +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Airport', + fields=[ + ('icao', models.CharField(max_length=4, primary_key=True, serialize=False)), + ], + ), + migrations.CreateModel( + name='Plane', + fields=[ + ('tail_number', models.CharField(max_length=64, primary_key=True, serialize=False)), + ('name', models.CharField(max_length=64)), + ('manufacturer', models.CharField(max_length=64)), + ('model', models.CharField(max_length=64)), + ], + ), + migrations.CreateModel( + name='Flight', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('flight_date', models.DateField()), + ('instructor', models.CharField(blank=True, max_length=64)), + ('remarks', models.TextField(blank=True)), + ('landings', models.IntegerField()), + ('airplane_sel_time', models.DecimalField(decimal_places=1, default=Decimal('0'), max_digits=2)), + ('airplane_mel_time', models.DecimalField(decimal_places=1, default=Decimal('0'), max_digits=2)), + ('cross_country_time', models.DecimalField(decimal_places=1, default=Decimal('0'), max_digits=2)), + ('day_time', models.DecimalField(decimal_places=1, default=Decimal('0'), max_digits=2)), + ('night_time', models.DecimalField(decimal_places=1, default=Decimal('0'), max_digits=2)), + ('actual_instrument_time', models.DecimalField(decimal_places=1, default=Decimal('0'), max_digits=2)), + ('simulated_instrument_time', models.DecimalField(decimal_places=1, default=Decimal('0'), max_digits=2)), + ('ground_trainer_time', models.DecimalField(decimal_places=1, default=Decimal('0'), max_digits=2)), + ('dual_received_time', models.DecimalField(decimal_places=1, default=Decimal('0'), max_digits=2)), + ('pilot_in_command_time', models.DecimalField(decimal_places=1, default=Decimal('0'), max_digits=2)), + ('total_time', models.DecimalField(decimal_places=1, default=Decimal('0'), max_digits=2)), + ('link', models.CharField(blank=True, max_length=200)), + ('airport_arrive', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='flight_to', to='flight.Airport')), + ('airport_depart', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='flight_from', to='flight.Airport')), + ('plane', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='flight.Plane')), + ], + ), + ] diff --git a/logbook/flight/migrations/__init__.py b/logbook/flight/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/logbook/flight/models.py b/logbook/flight/models.py new file mode 100644 index 0000000..b6e092c --- /dev/null +++ b/logbook/flight/models.py @@ -0,0 +1,46 @@ +from django.db import models +from decimal import Decimal +# Create your models here. + +class Plane(models.Model): + tail_number = models.CharField(max_length=64, primary_key=True) # "N43337" + name = models.CharField(max_length=64) # "Warrior II" + manufacturer = models.CharField(max_length=64) # Piper + model = models.CharField(max_length=64) # PA28-151 + + def __str__ (self): + return self.tail_number + +class Airport(models.Model): + icao = models.CharField(max_length=4, primary_key=True) + + def __str__ (self): + return self.icao + +class Flight(models.Model): + flight_date = models.DateField() # "flight_date": "2019-08-31", + plane = models.ForeignKey(Plane, on_delete=models.PROTECT) + instructor = models.CharField(max_length=64, blank=True) # "instructor": "Gene Moody", + remarks = models.TextField(blank=True) # "remarks": "normal to/l, shortfield to/l, std turns, constant speed, constant descents", + + airport_depart = models.ForeignKey(Airport, on_delete=models.PROTECT, related_name='%(class)s_from') # "from": "KEEN", + airport_arrive = models.ForeignKey(Airport, on_delete=models.PROTECT, related_name='%(class)s_to') # "to": "KEEN", + + landings = models.IntegerField() + + airplane_sel_time = models.DecimalField(max_digits=2, decimal_places=1, default=Decimal(0.0)) + airplane_mel_time = models.DecimalField(max_digits=2, decimal_places=1, default=Decimal(0.0)) + cross_country_time = models.DecimalField(max_digits=2, decimal_places=1, default=Decimal(0.0)) + day_time = models.DecimalField(max_digits=2, decimal_places=1, default=Decimal(0.0)) + night_time = models.DecimalField(max_digits=2, decimal_places=1, default=Decimal(0.0)) + actual_instrument_time = models.DecimalField(decimal_places=1,max_digits=2, default=Decimal(0.0)) + simulated_instrument_time = models.DecimalField(max_digits=2, decimal_places=1, default=Decimal(0.0)) + ground_trainer_time = models.DecimalField(max_digits=2, decimal_places=1, default=Decimal(0.0)) + dual_received_time = models.DecimalField(max_digits=2, decimal_places=1, default=Decimal(0.0)) + pilot_in_command_time = models.DecimalField(max_digits=2, decimal_places=1, default=Decimal(0.0)) + total_time = models.DecimalField(max_digits=2, decimal_places=1, default=Decimal(0.0)) + + link = models.CharField(max_length=200, blank=True) + + def __str__(self): + return f"{self.plane} {self.total_time}h - {self.airport_depart} -> {self.airport_arrive}" diff --git a/logbook/flight/tests.py b/logbook/flight/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/logbook/flight/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/logbook/flight/views.py b/logbook/flight/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/logbook/flight/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/logbook/logbook/settings.py b/logbook/logbook/settings.py index 5d4d543..70fb6de 100644 --- a/logbook/logbook/settings.py +++ b/logbook/logbook/settings.py @@ -29,7 +29,8 @@ INSTALLED_APPS = [ 'rest_framework', 'rest_framework.authtoken', - 'corsheaders' + 'corsheaders', + 'flight', ] MIDDLEWARE = [ @@ -68,8 +69,12 @@ WSGI_APPLICATION = 'logbook.wsgi.application' DATABASES = { 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + 'ENGINE': 'django.db.backends.postgresql', + 'NAME': 'logbook', + 'USER': os.environ.get('DJANGO_DB_NAME', ''), + 'PASSWORD': os.environ.get('DJANGO_DB_PASS', ''), + 'HOST': '127.0.0.1', + 'PORT': '5433', } } diff --git a/logbook/logbook/urls.py b/logbook/logbook/urls.py index 1a86ad3..a4eb489 100644 --- a/logbook/logbook/urls.py +++ b/logbook/logbook/urls.py @@ -18,8 +18,4 @@ from django.urls import path urlpatterns = [ path('admin/', admin.site.urls), - url(r'^api/v1/auth/obtain_token/', obtain_jwt_token), - url(r'^api/v1/auth/refresh_token/', refresh_jwt_token), - # The rest of the endpoints - url(r'^api/v1/', include('project.api', namespace='apiv1')), ] diff --git a/readme b/readme deleted file mode 100644 index 31d85e0..0000000 --- a/readme +++ /dev/null @@ -1 +0,0 @@ -https://www.pydanny.com/drf-jwt-axios-vue.html diff --git a/requirements.txt b/requirements.txt index e45c7c3..c40e769 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,8 @@ -Django -djangorestframework -django-cors-headers -djangorestframework-jwt - +Django==2.2.5 +django-cors-headers==3.1.0 +djangorestframework==3.10.3 +djangorestframework-jwt==1.11.0 +psycopg2==2.8.3 +PyJWT==1.7.1 +pytz==2019.2 +sqlparse==0.3.0