From 92a76fd3852ef19fecb77dd4953ee50105b08d84 Mon Sep 17 00:00:00 2001 From: Philip Bartoo Date: Wed, 5 Jan 2022 12:48:16 -0800 Subject: [PATCH 1/5] Philip-Django-Lab01_Todo Completed Version 1 --- .../Django/Lab01_Todo/todo_project/manage.py | 22 +++ .../Lab01_Todo/todo_project/static/index.css | 62 ++++++++ .../todo_project/templates/base.html | 11 ++ .../templates/todo_app/todo_form.html | 32 +++++ .../todo_project/todo_app/__init__.py | 0 .../Lab01_Todo/todo_project/todo_app/admin.py | 12 ++ .../Lab01_Todo/todo_project/todo_app/apps.py | 6 + .../todo_app/migrations/0001_initial.py | 32 +++++ .../0002_alter_priority_priority.py | 18 +++ .../migrations/0003_todo_created_date.py | 20 +++ .../todo_app/migrations/__init__.py | 0 .../todo_project/todo_app/models.py | 17 +++ .../todo_app/templates/index.html | 66 +++++++++ .../todo_app/templates/todo_detail.html | 35 +++++ .../Lab01_Todo/todo_project/todo_app/tests.py | 3 + .../Lab01_Todo/todo_project/todo_app/views.py | 63 +++++++++ .../todo_project/todo_project/__init__.py | 0 .../todo_project/todo_project/asgi.py | 16 +++ .../todo_project/todo_project/settings.py | 133 ++++++++++++++++++ .../todo_project/todo_project/urls.py | 14 ++ .../todo_project/todo_project/wsgi.py | 16 +++ 21 files changed, 578 insertions(+) create mode 100755 Code/Philip/Django/Lab01_Todo/todo_project/manage.py create mode 100644 Code/Philip/Django/Lab01_Todo/todo_project/static/index.css create mode 100644 Code/Philip/Django/Lab01_Todo/todo_project/templates/base.html create mode 100644 Code/Philip/Django/Lab01_Todo/todo_project/templates/todo_app/todo_form.html create mode 100644 Code/Philip/Django/Lab01_Todo/todo_project/todo_app/__init__.py create mode 100644 Code/Philip/Django/Lab01_Todo/todo_project/todo_app/admin.py create mode 100644 Code/Philip/Django/Lab01_Todo/todo_project/todo_app/apps.py create mode 100644 Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0001_initial.py create mode 100644 Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0002_alter_priority_priority.py create mode 100644 Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0003_todo_created_date.py create mode 100644 Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/__init__.py create mode 100644 Code/Philip/Django/Lab01_Todo/todo_project/todo_app/models.py create mode 100644 Code/Philip/Django/Lab01_Todo/todo_project/todo_app/templates/index.html create mode 100644 Code/Philip/Django/Lab01_Todo/todo_project/todo_app/templates/todo_detail.html create mode 100644 Code/Philip/Django/Lab01_Todo/todo_project/todo_app/tests.py create mode 100644 Code/Philip/Django/Lab01_Todo/todo_project/todo_app/views.py create mode 100644 Code/Philip/Django/Lab01_Todo/todo_project/todo_project/__init__.py create mode 100644 Code/Philip/Django/Lab01_Todo/todo_project/todo_project/asgi.py create mode 100644 Code/Philip/Django/Lab01_Todo/todo_project/todo_project/settings.py create mode 100644 Code/Philip/Django/Lab01_Todo/todo_project/todo_project/urls.py create mode 100644 Code/Philip/Django/Lab01_Todo/todo_project/todo_project/wsgi.py diff --git a/Code/Philip/Django/Lab01_Todo/todo_project/manage.py b/Code/Philip/Django/Lab01_Todo/todo_project/manage.py new file mode 100755 index 00000000..1d0193af --- /dev/null +++ b/Code/Philip/Django/Lab01_Todo/todo_project/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'todo_project.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/Code/Philip/Django/Lab01_Todo/todo_project/static/index.css b/Code/Philip/Django/Lab01_Todo/todo_project/static/index.css new file mode 100644 index 00000000..dfa2fb8a --- /dev/null +++ b/Code/Philip/Django/Lab01_Todo/todo_project/static/index.css @@ -0,0 +1,62 @@ +@import url('https://fonts.googleapis.com/css2?family=Ubuntu:ital@1&display=swap'); + +header { + background: slategray; + padding: 30px 40px; + color: white; + text-align: center; +} + +h1 { + font-family: 'Ubuntu', sans-serif; + margin-bottom: 15px;; + text-align: center; +} + +ul li { + cursor: pointer; + position: relative; + padding: 4px 4px 4px 20px; + list-style-type: none; + background: rgba(105, 90, 205, 0.096); + font-size: 18px; + transition: 0.2s; + margin: 3%; + border-radius: 20px; + border-color:slateblue; + border-width:.2em; + border-style:solid; + font-family: 'Ubuntu', sans-serif; +} + +ul li:hover { + background: rgba(105, 90, 205, 0.288) +} + +.subtask { + background-color: rgba(137, 43, 226, 0.397); + border-color:rgba(137, 43, 226, 0.11) +} + +.completed { + text-decoration: line-through; + border-color:#555; + background: rgb(145, 163, 182); + color: #fff; +} + +.new-todo { + text-align: center; + font-size: xx-large; +} + +a:link, a:visited, a:hover{ + text-decoration:none; + color:#555; +} + +.fas:hover { + border-radius: 50%; + background-color: rgba(75, 109, 139, 0.445); + color: white; +} \ No newline at end of file diff --git a/Code/Philip/Django/Lab01_Todo/todo_project/templates/base.html b/Code/Philip/Django/Lab01_Todo/todo_project/templates/base.html new file mode 100644 index 00000000..d901b063 --- /dev/null +++ b/Code/Philip/Django/Lab01_Todo/todo_project/templates/base.html @@ -0,0 +1,11 @@ +{% load static%} + + + + + + + {% block content%} + {% endblock %} + + \ No newline at end of file diff --git a/Code/Philip/Django/Lab01_Todo/todo_project/templates/todo_app/todo_form.html b/Code/Philip/Django/Lab01_Todo/todo_project/templates/todo_app/todo_form.html new file mode 100644 index 00000000..16ad342e --- /dev/null +++ b/Code/Philip/Django/Lab01_Todo/todo_project/templates/todo_app/todo_form.html @@ -0,0 +1,32 @@ +{% load static %} + + + + + + + New Honey Do + + + + + + +
+
+
+
+
+

New Honey Do


+
+ {% csrf_token%} + {{ form }} +

+ +
+
+
+
+
+
+ diff --git a/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/__init__.py b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/admin.py b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/admin.py new file mode 100644 index 00000000..9ad62fb0 --- /dev/null +++ b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/admin.py @@ -0,0 +1,12 @@ +from django.contrib import admin + +from .models import Todo +from .models import Priority + +@admin.register(Todo) +class TodoAdmin(admin.ModelAdmin): + list_display=['title','created_date','priority_choice','completed'] + +@admin.register(Priority) +class PriorityAdmin(admin.ModelAdmin): + list_display=['priority'] \ No newline at end of file diff --git a/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/apps.py b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/apps.py new file mode 100644 index 00000000..d8f1498d --- /dev/null +++ b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class TodoAppConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'todo_app' diff --git a/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0001_initial.py b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0001_initial.py new file mode 100644 index 00000000..a9709512 --- /dev/null +++ b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0001_initial.py @@ -0,0 +1,32 @@ +# Generated by Django 3.2.7 on 2021-12-30 02:11 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Priority', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('priority', models.CharField(choices=[('H', 'High'), ('M', 'Medium'), ('L', 'Low')], max_length=100)), + ], + ), + migrations.CreateModel( + name='Todo', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=100)), + ('completed', models.BooleanField(default=False)), + ('completed_date', models.DateTimeField(blank=True, null=True)), + ('priority_choice', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='todo_app.priority')), + ], + ), + ] diff --git a/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0002_alter_priority_priority.py b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0002_alter_priority_priority.py new file mode 100644 index 00000000..1f28006d --- /dev/null +++ b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0002_alter_priority_priority.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.7 on 2021-12-30 03:07 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('todo_app', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='priority', + name='priority', + field=models.CharField(max_length=7), + ), + ] diff --git a/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0003_todo_created_date.py b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0003_todo_created_date.py new file mode 100644 index 00000000..e3a89ed3 --- /dev/null +++ b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0003_todo_created_date.py @@ -0,0 +1,20 @@ +# Generated by Django 3.2.7 on 2021-12-30 04:33 + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('todo_app', '0002_alter_priority_priority'), + ] + + operations = [ + migrations.AddField( + model_name='todo', + name='created_date', + field=models.DateTimeField(auto_now_add=True, default=django.utils.timezone.now), + preserve_default=False, + ), + ] diff --git a/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/__init__.py b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/models.py b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/models.py new file mode 100644 index 00000000..ceeb5a71 --- /dev/null +++ b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/models.py @@ -0,0 +1,17 @@ +from django.db import models + +class Priority(models.Model): + priority = models.CharField(max_length=7) + + def __str__(self): + return self.priority + +class Todo(models.Model): + title = models.CharField(max_length=100) + created_date = models.DateTimeField(auto_now_add=True) + completed = models.BooleanField(default=False) + completed_date = models.DateTimeField(null=True, blank=True) + priority_choice = models.ForeignKey(Priority, on_delete=models.CASCADE, blank=True, null=True) + + def __str__(self): + return self.title \ No newline at end of file diff --git a/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/templates/index.html b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/templates/index.html new file mode 100644 index 00000000..95e2dd6d --- /dev/null +++ b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/templates/index.html @@ -0,0 +1,66 @@ +{% load static %} + + + + + + + + Honey Do List + + + + + + +
+
+
+
+
+
+

Honey Do List

+

Today is: {% now "jS F Y" %}

+
+ + +
+
+
+
+
+ +
+ +
+ +
+
+ +
    + + {% for each_todo in items%} + +
  • {{each_todo.title}} + +
      +
    • Priority: {{each_todo.priority_choice}}
    • +
    • Created: {{each_todo.created_date}}
    • +
    +
  • + {% endfor %} +
+
+
+
+
+ + + + + \ No newline at end of file diff --git a/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/templates/todo_detail.html b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/templates/todo_detail.html new file mode 100644 index 00000000..f60e18bc --- /dev/null +++ b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/templates/todo_detail.html @@ -0,0 +1,35 @@ +{% load static %} + + + + + + + New Honey Do + + + + + + + + + + + diff --git a/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/tests.py b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/views.py b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/views.py new file mode 100644 index 00000000..ef5037d0 --- /dev/null +++ b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/views.py @@ -0,0 +1,63 @@ +from django.shortcuts import render + +from datetime import datetime +from django.views.generic import CreateView, ListView + +from .models import Todo + +#Using class based views +#List View for main page +class TodoListView(ListView): + model = Todo + context_object_name = "items" + template_name = "index.html" + +#Create item view +class TodoCreateView(CreateView): + model = Todo + fields = ['title','priority_choice'] + success_url = '/index' + + + + + + + + + +#Function based views +'''def index(request): + all_todos = Todo.objects.all() + return render(request, 'index.html',{ + 'all_todos':all_todos, + }) + +def details(request, item_id): + each_todo = Todo.objects.get(id=item_id) + return render(request, 'save_todo_item.html', { + 'each_todo':each_todo, + }) + +def save_todo_item(request,item_id): + new_todo = Todo.objects.create() + +def todo_detail(request, item_id): + item = Todo.objects.get(id=item_id) + return render(request, 'todo_detail.html', {'item':item,}) + +class TodoCreateView(CreateView): + model = Todo + fields = ['title','priority_choice'] + success_url = '/index' + +class TodoUpdateView(UpdateView): + model = Todo + fields = ['title','priority_choice','complete','completed_date'] + success_url = '/index' + +class TodoDetailView(DetailView): + model = Todo + context_object_name = 'todo_detail' + template_name = 'todo_detail.html' + ''' \ No newline at end of file diff --git a/Code/Philip/Django/Lab01_Todo/todo_project/todo_project/__init__.py b/Code/Philip/Django/Lab01_Todo/todo_project/todo_project/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/Code/Philip/Django/Lab01_Todo/todo_project/todo_project/asgi.py b/Code/Philip/Django/Lab01_Todo/todo_project/todo_project/asgi.py new file mode 100644 index 00000000..e793c4bc --- /dev/null +++ b/Code/Philip/Django/Lab01_Todo/todo_project/todo_project/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for todo_project 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', 'todo_project.settings') + +application = get_asgi_application() diff --git a/Code/Philip/Django/Lab01_Todo/todo_project/todo_project/settings.py b/Code/Philip/Django/Lab01_Todo/todo_project/todo_project/settings.py new file mode 100644 index 00000000..a4d0ca5f --- /dev/null +++ b/Code/Philip/Django/Lab01_Todo/todo_project/todo_project/settings.py @@ -0,0 +1,133 @@ +""" +Django settings for todo_project project. + +Generated by 'django-admin startproject' using Django 3.2.7. + +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-0x+1)7@!sce-o_aq^o%&220z!$_17s0*i=pk5-bj3vi7cbi=hc' + +# 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', + + 'todo_app', +] + +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 = 'todo_project.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': ['templates', + BASE_DIR / 'static', + ], + '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 = 'todo_project.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 = 'UTC' + +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/' + #helps to lead Django to our static url +STATICFILES_DIRS = [ + BASE_DIR / '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/Philip/Django/Lab01_Todo/todo_project/todo_project/urls.py b/Code/Philip/Django/Lab01_Todo/todo_project/todo_project/urls.py new file mode 100644 index 00000000..3eb29953 --- /dev/null +++ b/Code/Philip/Django/Lab01_Todo/todo_project/todo_project/urls.py @@ -0,0 +1,14 @@ +from django.contrib import admin +from django.urls import path + +from todo_app import views + +urlpatterns = [ + path('admin/', admin.site.urls), + path('', views.TodoListView.as_view(), name='home.list'), + #path('/', views.TodoDetailView.as_view(), name='todo_detail'), + path('index/', views.TodoListView.as_view(), name='index.list'), + path('todo_form/', views.TodoCreateView.as_view(), name='todo_form.new'), + # path('details/', views.TodoDetailView.as_view(), name='todo_form.details') + +] diff --git a/Code/Philip/Django/Lab01_Todo/todo_project/todo_project/wsgi.py b/Code/Philip/Django/Lab01_Todo/todo_project/todo_project/wsgi.py new file mode 100644 index 00000000..5c559837 --- /dev/null +++ b/Code/Philip/Django/Lab01_Todo/todo_project/todo_project/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for todo_project 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', 'todo_project.settings') + +application = get_wsgi_application() From 0d5d6bc507dcc3303a9b5ac380c2a6c977fea163 Mon Sep 17 00:00:00 2001 From: Philip Bartoo Date: Wed, 5 Jan 2022 12:58:14 -0800 Subject: [PATCH 2/5] Philip-Django-Lab01_Todo Removed Secret Key --- .../Django/Lab01_Todo/todo_project/todo_project/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Code/Philip/Django/Lab01_Todo/todo_project/todo_project/settings.py b/Code/Philip/Django/Lab01_Todo/todo_project/todo_project/settings.py index a4d0ca5f..c2d83a34 100644 --- a/Code/Philip/Django/Lab01_Todo/todo_project/todo_project/settings.py +++ b/Code/Philip/Django/Lab01_Todo/todo_project/todo_project/settings.py @@ -20,7 +20,7 @@ # 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-0x+1)7@!sce-o_aq^o%&220z!$_17s0*i=pk5-bj3vi7cbi=hc' + # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True From 79a0a5954da064b09dd8e6d270be194379105cd4 Mon Sep 17 00:00:00 2001 From: Philip Bartoo Date: Fri, 7 Jan 2022 20:42:25 -0800 Subject: [PATCH 3/5] Philip-Django-Lab01_Todo Updated Jinja in index.html --- .../Lab01_Todo/todo_project/todo_app/templates/index.html | 3 ++- .../Django/Lab01_Todo/todo_project/todo_project/settings.py | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/templates/index.html b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/templates/index.html index 95e2dd6d..b9b91aa5 100644 --- a/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/templates/index.html +++ b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/templates/index.html @@ -40,7 +40,8 @@

Honey Do List

    diff --git a/Code/Philip/Django/Lab01_Todo/todo_project/todo_project/settings.py b/Code/Philip/Django/Lab01_Todo/todo_project/todo_project/settings.py index c2d83a34..a4d0ca5f 100644 --- a/Code/Philip/Django/Lab01_Todo/todo_project/todo_project/settings.py +++ b/Code/Philip/Django/Lab01_Todo/todo_project/todo_project/settings.py @@ -20,7 +20,7 @@ # 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-0x+1)7@!sce-o_aq^o%&220z!$_17s0*i=pk5-bj3vi7cbi=hc' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True From a3a51c51e730985a32aedb28dc35a2814399110e Mon Sep 17 00:00:00 2001 From: Philip Bartoo Date: Wed, 12 Jan 2022 17:21:34 -0800 Subject: [PATCH 4/5] Philip-Django-Lab01_Todo Added Priorities --- .../0004_remove_priority_priority.py | 17 +++++++++++++ .../migrations/0005_priority_priority.py | 18 ++++++++++++++ .../migrations/0006_auto_20220112_0302.py | 24 +++++++++++++++++++ .../0007_alter_todo_priority_choice.py | 19 +++++++++++++++ .../0008_alter_priority_priority.py | 18 ++++++++++++++ .../0009_alter_priority_priority.py | 18 ++++++++++++++ .../0010_alter_priority_priority.py | 18 ++++++++++++++ .../todo_project/todo_app/models.py | 19 +++++++++++---- 8 files changed, 146 insertions(+), 5 deletions(-) create mode 100644 Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0004_remove_priority_priority.py create mode 100644 Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0005_priority_priority.py create mode 100644 Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0006_auto_20220112_0302.py create mode 100644 Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0007_alter_todo_priority_choice.py create mode 100644 Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0008_alter_priority_priority.py create mode 100644 Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0009_alter_priority_priority.py create mode 100644 Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0010_alter_priority_priority.py diff --git a/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0004_remove_priority_priority.py b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0004_remove_priority_priority.py new file mode 100644 index 00000000..77f83ef6 --- /dev/null +++ b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0004_remove_priority_priority.py @@ -0,0 +1,17 @@ +# Generated by Django 3.2.7 on 2022-01-12 02:45 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('todo_app', '0003_todo_created_date'), + ] + + operations = [ + migrations.RemoveField( + model_name='priority', + name='priority', + ), + ] diff --git a/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0005_priority_priority.py b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0005_priority_priority.py new file mode 100644 index 00000000..7b18a403 --- /dev/null +++ b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0005_priority_priority.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.7 on 2022-01-12 02:55 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('todo_app', '0004_remove_priority_priority'), + ] + + operations = [ + migrations.AddField( + model_name='priority', + name='priority', + field=models.CharField(choices=[('LOW', 'low'), ('MEDIUM', 'medium'), ('HIGH', 'high')], default='low', max_length=7), + ), + ] diff --git a/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0006_auto_20220112_0302.py b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0006_auto_20220112_0302.py new file mode 100644 index 00000000..ff84158e --- /dev/null +++ b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0006_auto_20220112_0302.py @@ -0,0 +1,24 @@ +# Generated by Django 3.2.7 on 2022-01-12 03:02 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('todo_app', '0005_priority_priority'), + ] + + operations = [ + migrations.AlterField( + model_name='priority', + name='priority', + field=models.CharField(choices=[('LOW', 'low'), ('MEDIUM', 'medium'), ('HIGH', 'high')], max_length=7), + ), + migrations.AlterField( + model_name='todo', + name='priority_choice', + field=models.ForeignKey(blank=True, default='low', null=True, on_delete=django.db.models.deletion.CASCADE, to='todo_app.priority'), + ), + ] diff --git a/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0007_alter_todo_priority_choice.py b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0007_alter_todo_priority_choice.py new file mode 100644 index 00000000..c174fb09 --- /dev/null +++ b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0007_alter_todo_priority_choice.py @@ -0,0 +1,19 @@ +# Generated by Django 3.2.7 on 2022-01-12 03:03 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('todo_app', '0006_auto_20220112_0302'), + ] + + operations = [ + migrations.AlterField( + model_name='todo', + name='priority_choice', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='todo_app.priority'), + ), + ] diff --git a/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0008_alter_priority_priority.py b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0008_alter_priority_priority.py new file mode 100644 index 00000000..f6988ac4 --- /dev/null +++ b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0008_alter_priority_priority.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.7 on 2022-01-12 04:03 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('todo_app', '0007_alter_todo_priority_choice'), + ] + + operations = [ + migrations.AlterField( + model_name='priority', + name='priority', + field=models.CharField(max_length=20), + ), + ] diff --git a/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0009_alter_priority_priority.py b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0009_alter_priority_priority.py new file mode 100644 index 00000000..6eee2308 --- /dev/null +++ b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0009_alter_priority_priority.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.7 on 2022-01-12 04:10 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('todo_app', '0008_alter_priority_priority'), + ] + + operations = [ + migrations.AlterField( + model_name='priority', + name='priority', + field=models.CharField(choices=[('low', 'Low'), ('medium', 'Medium'), ('high', 'High')], default='low', max_length=20), + ), + ] diff --git a/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0010_alter_priority_priority.py b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0010_alter_priority_priority.py new file mode 100644 index 00000000..d5f9e7e1 --- /dev/null +++ b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/migrations/0010_alter_priority_priority.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.7 on 2022-01-12 04:14 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('todo_app', '0009_alter_priority_priority'), + ] + + operations = [ + migrations.AlterField( + model_name='priority', + name='priority', + field=models.CharField(choices=[('low', 'Low'), ('medium', 'Medium'), ('high', 'High')], max_length=20), + ), + ] diff --git a/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/models.py b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/models.py index ceeb5a71..e1adcf56 100644 --- a/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/models.py +++ b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/models.py @@ -1,8 +1,17 @@ from django.db import models +from django.db.models.deletion import SET_DEFAULT +from django.db.models.fields import CharField +from django.db import models + +CHOICES=[ + ('low','Low'), + ('medium','Medium'), + ('high','High'), +] + +class Priority(models.Model): + priority= models.CharField(choices=CHOICES,max_length=20) -class Priority(models.Model): - priority = models.CharField(max_length=7) - def __str__(self): return self.priority @@ -11,7 +20,7 @@ class Todo(models.Model): created_date = models.DateTimeField(auto_now_add=True) completed = models.BooleanField(default=False) completed_date = models.DateTimeField(null=True, blank=True) - priority_choice = models.ForeignKey(Priority, on_delete=models.CASCADE, blank=True, null=True) + priority_choice = models.ForeignKey(Priority,on_delete=models.CASCADE, blank=True, null=True) def __str__(self): - return self.title \ No newline at end of file + return self.title + self.priority_choice \ No newline at end of file From 745ccfc5d96a81d22a17ed3caeda1d6206fe7256 Mon Sep 17 00:00:00 2001 From: Philip Bartoo Date: Fri, 14 Jan 2022 15:11:21 -0800 Subject: [PATCH 5/5] Philip-Django-Lab01_Todo Added .objects.get_or_create to Model --- .../Lab01_Todo/todo_project/todo_app/models.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/models.py b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/models.py index e1adcf56..7ff99955 100644 --- a/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/models.py +++ b/Code/Philip/Django/Lab01_Todo/todo_project/todo_app/models.py @@ -3,18 +3,18 @@ from django.db.models.fields import CharField from django.db import models -CHOICES=[ - ('low','Low'), - ('medium','Medium'), - ('high','High'), -] + class Priority(models.Model): - priority= models.CharField(choices=CHOICES,max_length=20) + priority= models.CharField(max_length=20) def __str__(self): return self.priority +priority, created = Priority.objects.get_or_create(priority='High') +priority, created = Priority.objects.get_or_create(priority='Medium') +priority, created = Priority.objects.get_or_create(priority='Low') + class Todo(models.Model): title = models.CharField(max_length=100) created_date = models.DateTimeField(auto_now_add=True)