From 813458db8bc04c705382fea8501c49b6389d1948 Mon Sep 17 00:00:00 2001 From: asddataking Date: Fri, 6 May 2022 18:42:49 -0400 Subject: [PATCH 1/2] Django Lab 2 --- .../dan/django/lab2/config/config/__init__.py | 0 code/dan/django/lab2/config/config/asgi.py | 16 +++ .../dan/django/lab2/config/config/settings.py | 126 ++++++++++++++++++ code/dan/django/lab2/config/config/urls.py | 22 +++ code/dan/django/lab2/config/config/wsgi.py | 16 +++ .../django/lab2/config/library/__init__.py | 0 code/dan/django/lab2/config/library/admin.py | 6 + code/dan/django/lab2/config/library/apps.py | 6 + code/dan/django/lab2/config/library/forms.py | 20 +++ .../config/library/migrations/0001_initial.py | 21 +++ .../migrations/0002_auto_20220505_1737.py | 44 ++++++ .../0003_alter_checkinout_checkouttime.py | 19 +++ .../migrations/0004_alter_book_author.py | 19 +++ .../migrations/0005_checkinout_in_out.py | 18 +++ .../0006_alter_checkinout_lengthofcheckout.py | 18 +++ .../0007_alter_checkinout_in_out.py | 18 +++ .../config/library/migrations/__init__.py | 0 code/dan/django/lab2/config/library/models.py | 24 ++++ .../library/templates/library/checkout.html | 26 ++++ .../library/templates/library/index.html | 41 ++++++ code/dan/django/lab2/config/library/tests.py | 3 + code/dan/django/lab2/config/library/urls.py | 9 ++ code/dan/django/lab2/config/library/views.py | 55 ++++++++ code/dan/django/lab2/config/manage.py | 22 +++ 24 files changed, 549 insertions(+) create mode 100644 code/dan/django/lab2/config/config/__init__.py create mode 100644 code/dan/django/lab2/config/config/asgi.py create mode 100644 code/dan/django/lab2/config/config/settings.py create mode 100644 code/dan/django/lab2/config/config/urls.py create mode 100644 code/dan/django/lab2/config/config/wsgi.py create mode 100644 code/dan/django/lab2/config/library/__init__.py create mode 100644 code/dan/django/lab2/config/library/admin.py create mode 100644 code/dan/django/lab2/config/library/apps.py create mode 100644 code/dan/django/lab2/config/library/forms.py create mode 100644 code/dan/django/lab2/config/library/migrations/0001_initial.py create mode 100644 code/dan/django/lab2/config/library/migrations/0002_auto_20220505_1737.py create mode 100644 code/dan/django/lab2/config/library/migrations/0003_alter_checkinout_checkouttime.py create mode 100644 code/dan/django/lab2/config/library/migrations/0004_alter_book_author.py create mode 100644 code/dan/django/lab2/config/library/migrations/0005_checkinout_in_out.py create mode 100644 code/dan/django/lab2/config/library/migrations/0006_alter_checkinout_lengthofcheckout.py create mode 100644 code/dan/django/lab2/config/library/migrations/0007_alter_checkinout_in_out.py create mode 100644 code/dan/django/lab2/config/library/migrations/__init__.py create mode 100644 code/dan/django/lab2/config/library/models.py create mode 100644 code/dan/django/lab2/config/library/templates/library/checkout.html create mode 100644 code/dan/django/lab2/config/library/templates/library/index.html create mode 100644 code/dan/django/lab2/config/library/tests.py create mode 100644 code/dan/django/lab2/config/library/urls.py create mode 100644 code/dan/django/lab2/config/library/views.py create mode 100644 code/dan/django/lab2/config/manage.py diff --git a/code/dan/django/lab2/config/config/__init__.py b/code/dan/django/lab2/config/config/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/code/dan/django/lab2/config/config/asgi.py b/code/dan/django/lab2/config/config/asgi.py new file mode 100644 index 00000000..8dad6029 --- /dev/null +++ b/code/dan/django/lab2/config/config/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for config project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings') + +application = get_asgi_application() diff --git a/code/dan/django/lab2/config/config/settings.py b/code/dan/django/lab2/config/config/settings.py new file mode 100644 index 00000000..99ef7aff --- /dev/null +++ b/code/dan/django/lab2/config/config/settings.py @@ -0,0 +1,126 @@ +""" +Django settings for config project. + +Generated by 'django-admin startproject' using Django 3.2.13. + +For more information on this file, see +https://docs.djangoproject.com/en/3.2/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/3.2/ref/settings/ +""" + +from pathlib import Path + +# Build paths inside the project like this: BASE_DIR / 'subdir'. +BASE_DIR = Path(__file__).resolve().parent.parent + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'django-insecure-@0yvlz6_2!#5-i-$k8z8a$5dzk*pb5!01d&yh!0ogywm#))lkr' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True + +ALLOWED_HOSTS = [] + + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'library.apps.LibraryConfig' +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'config.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'config.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/3.2/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/3.2/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'America/Detroit' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/3.2/howto/static-files/ + +STATIC_URL = '/static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/code/dan/django/lab2/config/config/urls.py b/code/dan/django/lab2/config/config/urls.py new file mode 100644 index 00000000..9e8014b7 --- /dev/null +++ b/code/dan/django/lab2/config/config/urls.py @@ -0,0 +1,22 @@ +"""config URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/3.2/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, include + +urlpatterns = [ + path('admin/', admin.site.urls), + path('', include('library.urls')) +] diff --git a/code/dan/django/lab2/config/config/wsgi.py b/code/dan/django/lab2/config/config/wsgi.py new file mode 100644 index 00000000..89156718 --- /dev/null +++ b/code/dan/django/lab2/config/config/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for config project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings') + +application = get_wsgi_application() diff --git a/code/dan/django/lab2/config/library/__init__.py b/code/dan/django/lab2/config/library/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/code/dan/django/lab2/config/library/admin.py b/code/dan/django/lab2/config/library/admin.py new file mode 100644 index 00000000..0187dedd --- /dev/null +++ b/code/dan/django/lab2/config/library/admin.py @@ -0,0 +1,6 @@ +from django.contrib import admin +from .models import Book, Author,Checkinout + +admin.site.register(Book) +admin.site.register(Author) +admin.site.register(Checkinout) \ No newline at end of file diff --git a/code/dan/django/lab2/config/library/apps.py b/code/dan/django/lab2/config/library/apps.py new file mode 100644 index 00000000..c33ac9c8 --- /dev/null +++ b/code/dan/django/lab2/config/library/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class LibraryConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'library' diff --git a/code/dan/django/lab2/config/library/forms.py b/code/dan/django/lab2/config/library/forms.py new file mode 100644 index 00000000..0be6e306 --- /dev/null +++ b/code/dan/django/lab2/config/library/forms.py @@ -0,0 +1,20 @@ +from django import forms +from django.forms import ModelForm +import datetime +from .models import Checkinout, Book + +class Checkinoutform(ModelForm): + class Meta: + model = Checkinout + fields='__all__' + + +class Addbookform(ModelForm): + class Meta: + model = Book + fields='__all__' + + + + + diff --git a/code/dan/django/lab2/config/library/migrations/0001_initial.py b/code/dan/django/lab2/config/library/migrations/0001_initial.py new file mode 100644 index 00000000..f05b3991 --- /dev/null +++ b/code/dan/django/lab2/config/library/migrations/0001_initial.py @@ -0,0 +1,21 @@ +# Generated by Django 3.2.13 on 2022-05-04 22:37 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='MyModel', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('myfield', models.CharField(max_length=200)), + ], + ), + ] diff --git a/code/dan/django/lab2/config/library/migrations/0002_auto_20220505_1737.py b/code/dan/django/lab2/config/library/migrations/0002_auto_20220505_1737.py new file mode 100644 index 00000000..b982f52c --- /dev/null +++ b/code/dan/django/lab2/config/library/migrations/0002_auto_20220505_1737.py @@ -0,0 +1,44 @@ +# Generated by Django 3.2.13 on 2022-05-05 21:37 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('library', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Author', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('first_name', models.CharField(max_length=50)), + ('last_name', models.CharField(max_length=50)), + ], + ), + migrations.CreateModel( + name='Book', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=200)), + ('pub_date', models.DateField()), + ('author', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='library.author')), + ], + ), + migrations.CreateModel( + name='Checkinout', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=200)), + ('checkouttime', models.DateTimeField(auto_now_add=True)), + ('name', models.CharField(max_length=200)), + ('lengthofcheckout', models.IntegerField()), + ], + ), + migrations.DeleteModel( + name='MyModel', + ), + ] diff --git a/code/dan/django/lab2/config/library/migrations/0003_alter_checkinout_checkouttime.py b/code/dan/django/lab2/config/library/migrations/0003_alter_checkinout_checkouttime.py new file mode 100644 index 00000000..9248f7d4 --- /dev/null +++ b/code/dan/django/lab2/config/library/migrations/0003_alter_checkinout_checkouttime.py @@ -0,0 +1,19 @@ +# Generated by Django 3.2.13 on 2022-05-06 18:11 + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('library', '0002_auto_20220505_1737'), + ] + + operations = [ + migrations.AlterField( + model_name='checkinout', + name='checkouttime', + field=models.DateTimeField(default=django.utils.timezone.now), + ), + ] diff --git a/code/dan/django/lab2/config/library/migrations/0004_alter_book_author.py b/code/dan/django/lab2/config/library/migrations/0004_alter_book_author.py new file mode 100644 index 00000000..61cb6581 --- /dev/null +++ b/code/dan/django/lab2/config/library/migrations/0004_alter_book_author.py @@ -0,0 +1,19 @@ +# Generated by Django 3.2.13 on 2022-05-06 21:08 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('library', '0003_alter_checkinout_checkouttime'), + ] + + operations = [ + migrations.AlterField( + model_name='book', + name='author', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to='library.author'), + ), + ] diff --git a/code/dan/django/lab2/config/library/migrations/0005_checkinout_in_out.py b/code/dan/django/lab2/config/library/migrations/0005_checkinout_in_out.py new file mode 100644 index 00000000..7c36dd8b --- /dev/null +++ b/code/dan/django/lab2/config/library/migrations/0005_checkinout_in_out.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.13 on 2022-05-06 21:17 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('library', '0004_alter_book_author'), + ] + + operations = [ + migrations.AddField( + model_name='checkinout', + name='in_out', + field=models.BooleanField(default=False, null=True), + ), + ] diff --git a/code/dan/django/lab2/config/library/migrations/0006_alter_checkinout_lengthofcheckout.py b/code/dan/django/lab2/config/library/migrations/0006_alter_checkinout_lengthofcheckout.py new file mode 100644 index 00000000..a8274d30 --- /dev/null +++ b/code/dan/django/lab2/config/library/migrations/0006_alter_checkinout_lengthofcheckout.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.13 on 2022-05-06 22:02 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('library', '0005_checkinout_in_out'), + ] + + operations = [ + migrations.AlterField( + model_name='checkinout', + name='lengthofcheckout', + field=models.IntegerField(null=True), + ), + ] diff --git a/code/dan/django/lab2/config/library/migrations/0007_alter_checkinout_in_out.py b/code/dan/django/lab2/config/library/migrations/0007_alter_checkinout_in_out.py new file mode 100644 index 00000000..163710ab --- /dev/null +++ b/code/dan/django/lab2/config/library/migrations/0007_alter_checkinout_in_out.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.13 on 2022-05-06 22:31 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('library', '0006_alter_checkinout_lengthofcheckout'), + ] + + operations = [ + migrations.AlterField( + model_name='checkinout', + name='in_out', + field=models.BooleanField(default=False, null=True, verbose_name='Checked Out'), + ), + ] diff --git a/code/dan/django/lab2/config/library/migrations/__init__.py b/code/dan/django/lab2/config/library/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/code/dan/django/lab2/config/library/models.py b/code/dan/django/lab2/config/library/models.py new file mode 100644 index 00000000..1dd77884 --- /dev/null +++ b/code/dan/django/lab2/config/library/models.py @@ -0,0 +1,24 @@ +from django.db import models +from django.utils import timezone +import datetime + +class Author(models.Model): + first_name = models.CharField(max_length=50) + last_name = models.CharField(max_length=50) + + +class Book(models.Model): + title = models.CharField(max_length=200) + pub_date = models.DateField() + author = models.ForeignKey('Author',on_delete=models.PROTECT, null=True) + + +class Checkinout(models.Model): + title = models.CharField(max_length=200) + name = models.CharField(max_length=200) + lengthofcheckout = models.IntegerField(null=True) + checkouttime = models.DateTimeField(default=timezone.now) + in_out = models.BooleanField(null=True,default=False,) + +def __str__(self): + return self.myfield \ No newline at end of file diff --git a/code/dan/django/lab2/config/library/templates/library/checkout.html b/code/dan/django/lab2/config/library/templates/library/checkout.html new file mode 100644 index 00000000..ec2adf44 --- /dev/null +++ b/code/dan/django/lab2/config/library/templates/library/checkout.html @@ -0,0 +1,26 @@ + + + + + + + +

{{ message }}

+ + + +

Checkout List

+ + + \ No newline at end of file diff --git a/code/dan/django/lab2/config/library/templates/library/index.html b/code/dan/django/lab2/config/library/templates/library/index.html new file mode 100644 index 00000000..56ed724b --- /dev/null +++ b/code/dan/django/lab2/config/library/templates/library/index.html @@ -0,0 +1,41 @@ + + + + + + + +

{{ message }}

+ + + +

Here are some of the Books available for checkout

+