Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
django = "*"
python-decouple = "*"

[requires]
python_version = "3.7"
43 changes: 43 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Empty file added djorg/__init__.py
Empty file.
122 changes: 122 additions & 0 deletions djorg/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
"""
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
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__)))


# 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 = config('SECRET_KEY')
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm glad you fixed this issue. Did you generate a new key since this one is still visible here?


# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = config('DEBUG', cast=bool)

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
'notes',
'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/'
21 changes: 21 additions & 0 deletions djorg/urls.py
Original file line number Diff line number Diff line change
@@ -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),
]
16 changes: 16 additions & 0 deletions djorg/wsgi.py
Original file line number Diff line number Diff line change
@@ -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()
60 changes: 30 additions & 30 deletions guides/day1.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,37 @@

* 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`
* `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`
* Add `'notes'` to `INSTALLED_APPS` in `djorg/settings.py`
* `./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`
* `pipenv --three` DONE!
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job with this checklist!

* `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` DONE!
* Add `'notes'` to `INSTALLED_APPS` in `djorg/settings.py` DONE!
* `./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
Expand Down
15 changes: 15 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -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)
Empty file added notes/__init__.py
Empty file.
12 changes: 12 additions & 0 deletions notes/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +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)
5 changes: 5 additions & 0 deletions notes/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class NotesConfig(AppConfig):
name = 'notes'
36 changes: 36 additions & 0 deletions notes/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -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',),
),
]
Empty file added notes/migrations/__init__.py
Empty file.
15 changes: 15 additions & 0 deletions notes/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +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)
3 changes: 3 additions & 0 deletions notes/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
3 changes: 3 additions & 0 deletions notes/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.shortcuts import render

# Create your views here.