From 759913fbc123ab54a82ad918b04fad546ef7cab3 Mon Sep 17 00:00:00 2001 From: Lucas Beemer Date: Mon, 3 Dec 2018 16:10:34 -0800 Subject: [PATCH 1/9] deleted requirements.text in Hello-Django --- guides/day1.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/day1.md b/guides/day1.md index cd54d6429..b56a4c83f 100644 --- a/guides/day1.md +++ b/guides/day1.md @@ -4,7 +4,7 @@ * Get pipenv installed * Clone your repo - * (If you cloned the Hello-Django repo, delete the file `requirements.txt`!) + * (If you cloned the Hello-Django repo, delete the file `requirements.txt`!) DONE! * Go to your repo root directory * `pipenv --three` * `pipenv install` From 675d5d4ffa19e4446cb731f39bdc8d2994a31dbe Mon Sep 17 00:00:00 2001 From: Lucas Beemer Date: Mon, 3 Dec 2018 16:44:24 -0800 Subject: [PATCH 2/9] set up --- Pipfile | 12 ++++ Pipfile.lock | 36 +++++++++++ djorg/__init__.py | 0 djorg/settings.py | 120 +++++++++++++++++++++++++++++++++++ djorg/urls.py | 21 ++++++ djorg/wsgi.py | 16 +++++ manage.py | 15 +++++ notes/__init__.py | 0 notes/admin.py | 3 + notes/apps.py | 5 ++ notes/migrations/__init__.py | 0 notes/models.py | 3 + notes/tests.py | 3 + notes/views.py | 3 + 14 files changed, 237 insertions(+) create mode 100644 Pipfile create mode 100644 Pipfile.lock create mode 100644 djorg/__init__.py create mode 100644 djorg/settings.py create mode 100644 djorg/urls.py create mode 100644 djorg/wsgi.py create mode 100755 manage.py create mode 100644 notes/__init__.py create mode 100644 notes/admin.py create mode 100644 notes/apps.py create mode 100644 notes/migrations/__init__.py create mode 100644 notes/models.py create mode 100644 notes/tests.py create mode 100644 notes/views.py diff --git a/Pipfile b/Pipfile new file mode 100644 index 000000000..967df8311 --- /dev/null +++ b/Pipfile @@ -0,0 +1,12 @@ +[[source]] +name = "pypi" +url = "https://pypi.org/simple" +verify_ssl = true + +[dev-packages] + +[packages] +django = "*" + +[requires] +python_version = "3.7" diff --git a/Pipfile.lock b/Pipfile.lock new file mode 100644 index 000000000..76307f4d0 --- /dev/null +++ b/Pipfile.lock @@ -0,0 +1,36 @@ +{ + "_meta": { + "hash": { + "sha256": "627ef89f247ecee27e9ef0dabe116108d09c47abf171c900a8817befa64f9dd2" + }, + "pipfile-spec": 6, + "requires": { + "python_version": "3.7" + }, + "sources": [ + { + "name": "pypi", + "url": "https://pypi.org/simple", + "verify_ssl": true + } + ] + }, + "default": { + "django": { + "hashes": [ + "sha256:068d51054083d06ceb32ce02b7203f1854256047a0d58682677dd4f81bceabd7", + "sha256:55409a056b27e6d1246f19ede41c6c610e4cab549c005b62cbeefabc6433356b" + ], + "index": "pypi", + "version": "==2.1.4" + }, + "pytz": { + "hashes": [ + "sha256:31cb35c89bd7d333cd32c5f278fca91b523b0834369e757f4c5641ea252236ca", + "sha256:8e0f8568c118d3077b46be7d654cc8167fa916092e28320cde048e54bfc9f1e6" + ], + "version": "==2018.7" + } + }, + "develop": {} +} diff --git a/djorg/__init__.py b/djorg/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/djorg/settings.py b/djorg/settings.py new file mode 100644 index 000000000..909fe8b23 --- /dev/null +++ b/djorg/settings.py @@ -0,0 +1,120 @@ +""" +Django settings for djorg project. + +Generated by 'django-admin startproject' using Django 2.1.4. + +For more information on this file, see +https://docs.djangoproject.com/en/2.1/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/2.1/ref/settings/ +""" + +import os + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'g&amg2e#t7b&x(%an0w%ps$vfsne)-piwh3)y=!xw1l=tb3c*c' + +# 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', +] + +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 = 'djorg.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 = 'djorg.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/2.1/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), + } +} + + +# Password validation +# https://docs.djangoproject.com/en/2.1/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/2.1/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/2.1/howto/static-files/ + +STATIC_URL = '/static/' diff --git a/djorg/urls.py b/djorg/urls.py new file mode 100644 index 000000000..f4f667215 --- /dev/null +++ b/djorg/urls.py @@ -0,0 +1,21 @@ +"""djorg URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/2.1/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 + +urlpatterns = [ + path('admin/', admin.site.urls), +] diff --git a/djorg/wsgi.py b/djorg/wsgi.py new file mode 100644 index 000000000..7bb827bb0 --- /dev/null +++ b/djorg/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for djorg 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/2.1/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djorg.settings') + +application = get_wsgi_application() diff --git a/manage.py b/manage.py new file mode 100755 index 000000000..ae1e94bc6 --- /dev/null +++ b/manage.py @@ -0,0 +1,15 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == '__main__': + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'djorg.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) diff --git a/notes/__init__.py b/notes/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/notes/admin.py b/notes/admin.py new file mode 100644 index 000000000..8c38f3f3d --- /dev/null +++ b/notes/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/notes/apps.py b/notes/apps.py new file mode 100644 index 000000000..b6155aca3 --- /dev/null +++ b/notes/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class NotesConfig(AppConfig): + name = 'notes' diff --git a/notes/migrations/__init__.py b/notes/migrations/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/notes/models.py b/notes/models.py new file mode 100644 index 000000000..71a836239 --- /dev/null +++ b/notes/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/notes/tests.py b/notes/tests.py new file mode 100644 index 000000000..7ce503c2d --- /dev/null +++ b/notes/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/notes/views.py b/notes/views.py new file mode 100644 index 000000000..91ea44a21 --- /dev/null +++ b/notes/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. From 1b207fe8f380a115837748c7cfa0bdd1cbc09099 Mon Sep 17 00:00:00 2001 From: Lucas Beemer Date: Mon, 3 Dec 2018 16:54:14 -0800 Subject: [PATCH 3/9] more project setup --- guides/day1.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/guides/day1.md b/guides/day1.md index b56a4c83f..d34d2e7b1 100644 --- a/guides/day1.md +++ b/guides/day1.md @@ -6,17 +6,17 @@ * Clone your repo * (If you cloned the Hello-Django repo, delete the file `requirements.txt`!) DONE! * Go to your repo root directory -* `pipenv --three` -* `pipenv install` -* `pipenv shell` -* `pipenv install django` -* `django-admin startproject djorg .` -* `django-admin startapp notes` -* `./manage.py runserver` -* `./manage.py showmigrations` -* `./manage.py migrate` -* `./manage.py runserver` -* Add model to `notes/models.py` +* `pipenv --three` DONE! +* `pipenv install` DONE! +* `pipenv shell` DONE! +* `pipenv install django` DONE! +* `django-admin startproject djorg .` DONE! +* `django-admin startapp notes` DONE! +* `./manage.py runserver` DONE! +* `./manage.py showmigrations` DONE! +* `./manage.py migrate` DONE! +* `./manage.py runserver` DONE! +* Add model to `notes/models.py` * Add `'notes'` to `INSTALLED_APPS` in `djorg/settings.py` * `./manage.py showmigrations` * `./manage.py makemigrations` From 79ec0de80653c45891d0881a6f0cc9592cc0cde4 Mon Sep 17 00:00:00 2001 From: Lucas Beemer Date: Mon, 3 Dec 2018 20:19:41 -0800 Subject: [PATCH 4/9] created Note class using models --- djorg/settings.py | 1 + guides/day1.md | 4 ++-- notes/admin.py | 9 +++++++++ notes/models.py | 12 ++++++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/djorg/settings.py b/djorg/settings.py index 909fe8b23..9208140a6 100644 --- a/djorg/settings.py +++ b/djorg/settings.py @@ -31,6 +31,7 @@ # Application definition INSTALLED_APPS = [ + 'notes', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', diff --git a/guides/day1.md b/guides/day1.md index d34d2e7b1..56fec4e03 100644 --- a/guides/day1.md +++ b/guides/day1.md @@ -16,8 +16,8 @@ * `./manage.py showmigrations` DONE! * `./manage.py migrate` DONE! * `./manage.py runserver` DONE! -* Add model to `notes/models.py` -* Add `'notes'` to `INSTALLED_APPS` in `djorg/settings.py` +* Add model to `notes/models.py` DONE! +* Add `'notes'` to `INSTALLED_APPS` in `djorg/settings.py` DONE! * `./manage.py showmigrations` * `./manage.py makemigrations` * `./manage.py showmigrations` diff --git a/notes/admin.py b/notes/admin.py index 8c38f3f3d..44fdbe802 100644 --- a/notes/admin.py +++ b/notes/admin.py @@ -1,3 +1,12 @@ from django.contrib import admin +from .models import Note +from .models import PersonalNote # Register your models here. + +class NoteAdmin(admin.ModelAdmin): + readonly_fields=('created_at', 'last_modified') + + +admin.site.register(Note, NoteAdmin) +admin.site.register(PersonalNote) \ No newline at end of file diff --git a/notes/models.py b/notes/models.py index 71a836239..e5d0fb03f 100644 --- a/notes/models.py +++ b/notes/models.py @@ -1,3 +1,15 @@ from django.db import models +from uuid import uuid4 +from django.contrib.auth.models import User # Create your models here. + +class Note(models.Model): + id = models.UUIDField(primary_key=True, default=uuid4, editable=False) + title = models.CharField(max_length=200) + content = models.TextField(blank=True) + created_at = models.DateTimeField(auto_now_add=True) + last_modified = models.DateTimeField(auto_now=True) + +class PersonalNote(Note): + user = models.ForeignKey(User, on_delete=models.CASCADE) \ No newline at end of file From cec3bb7657ac0f9b28e1035d2786b8323581107f Mon Sep 17 00:00:00 2001 From: Lucas Beemer Date: Mon, 3 Dec 2018 20:30:32 -0800 Subject: [PATCH 5/9] first migration --- notes/migrations/0001_initial.py | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 notes/migrations/0001_initial.py diff --git a/notes/migrations/0001_initial.py b/notes/migrations/0001_initial.py new file mode 100644 index 000000000..2e6de5a55 --- /dev/null +++ b/notes/migrations/0001_initial.py @@ -0,0 +1,36 @@ +# Generated by Django 2.1.4 on 2018-12-04 04:27 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion +import uuid + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='Note', + fields=[ + ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), + ('title', models.CharField(max_length=200)), + ('content', models.TextField(blank=True)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('last_modified', models.DateTimeField(auto_now=True)), + ], + ), + migrations.CreateModel( + name='PersonalNote', + fields=[ + ('note_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='notes.Note')), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + bases=('notes.note',), + ), + ] From 78aeca7e87d9717feefaff1d8548e52547641e49 Mon Sep 17 00:00:00 2001 From: Lucas Beemer Date: Mon, 3 Dec 2018 20:50:57 -0800 Subject: [PATCH 6/9] installed python-decouple --- Pipfile | 1 + Pipfile.lock | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Pipfile b/Pipfile index 967df8311..86e1565e3 100644 --- a/Pipfile +++ b/Pipfile @@ -7,6 +7,7 @@ verify_ssl = true [packages] django = "*" +python-decouple = "*" [requires] python_version = "3.7" diff --git a/Pipfile.lock b/Pipfile.lock index 76307f4d0..666b71ab8 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "627ef89f247ecee27e9ef0dabe116108d09c47abf171c900a8817befa64f9dd2" + "sha256": "0bb3b331760d823d01166b55e53cd9c02ded57f108f27a6e4dd739e3ed291a1f" }, "pipfile-spec": 6, "requires": { @@ -24,6 +24,13 @@ "index": "pypi", "version": "==2.1.4" }, + "python-decouple": { + "hashes": [ + "sha256:1317df14b43efee4337a4aa02914bf004f010cd56d6c4bd894e6474ec8c4fe2d" + ], + "index": "pypi", + "version": "==3.1" + }, "pytz": { "hashes": [ "sha256:31cb35c89bd7d333cd32c5f278fca91b523b0834369e757f4c5641ea252236ca", From f096ec5cc782d682e8e493866cb1d1d34163e59c Mon Sep 17 00:00:00 2001 From: Lucas Beemer Date: Mon, 3 Dec 2018 22:14:06 -0800 Subject: [PATCH 7/9] having trouble w/ SEC KEY and .env --- djorg/settings.py | 1 + 1 file changed, 1 insertion(+) diff --git a/djorg/settings.py b/djorg/settings.py index 9208140a6..e0fb02ebe 100644 --- a/djorg/settings.py +++ b/djorg/settings.py @@ -11,6 +11,7 @@ """ import os +from decouple import config # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) From a5cd9f6690a773f5cd2720c57ac396ccee2244cc Mon Sep 17 00:00:00 2001 From: Lucas Beemer Date: Tue, 4 Dec 2018 08:15:13 -0800 Subject: [PATCH 8/9] finished day 1 mvp --- djorg/settings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/djorg/settings.py b/djorg/settings.py index e0fb02ebe..8e3588899 100644 --- a/djorg/settings.py +++ b/djorg/settings.py @@ -21,10 +21,10 @@ # See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'g&amg2e#t7b&x(%an0w%ps$vfsne)-piwh3)y=!xw1l=tb3c*c' +SECRET_KEY = config('SECRET_KEY') # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = config('DEBUG', cast=bool) ALLOWED_HOSTS = [] From 578dc559d54398f0602fc0f3ae11f9e3ce654da4 Mon Sep 17 00:00:00 2001 From: Lucas Beemer Date: Tue, 4 Dec 2018 08:57:42 -0800 Subject: [PATCH 9/9] updated day1 checklist --- guides/day1.md | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/guides/day1.md b/guides/day1.md index 56fec4e03..4adfd5e66 100644 --- a/guides/day1.md +++ b/guides/day1.md @@ -18,23 +18,23 @@ * `./manage.py runserver` DONE! * Add model to `notes/models.py` DONE! * Add `'notes'` to `INSTALLED_APPS` in `djorg/settings.py` DONE! -* `./manage.py showmigrations` -* `./manage.py makemigrations` -* `./manage.py showmigrations` -* `./manage.py migrate` -* `./manage.py shell` - * `from notes.models import Note` - * `n = Note(title=”example”, content=”This is a test.”)` - * `n.save()` - * `exit()` -* `./manage.py shell` - * `from notes.models import Note` - * `x = Note.objects.all()` - * `x[0]` - * `x[0].content` - * `exit()` -* `pipenv install python-decouple` -* Add config information to `settings.py` and `.env` +* `./manage.py showmigrations` DONE! +* `./manage.py makemigrations` DONE! +* `./manage.py showmigrations` DONE! +* `./manage.py migrate` DONE! +* `./manage.py shell` DONE! + * `from notes.models import Note` DONE! + * `n = Note(title=”example”, content=”This is a test.”)` DONE! + * `n.save()` DONE! + * `exit()` DONE! +* `./manage.py shell` DONE! + * `from notes.models import Note` DONE! + * `x = Note.objects.all()` DONE! + * `x[0]` DONE! + * `x[0].content` DONE! + * `exit()` DONE! +* `pipenv install python-decouple` DONE! +* Add config information to `settings.py` and `.env` DONE! ## Setting up a Virtual Environment