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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
56 changes: 56 additions & 0 deletions j_chris_miller_python/Django/PROJECT NOTES.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#Step by Step instructions for creating a new project:

0. Make sure youre in your virtual enviornment:
source DjangoEnv/Scripts/activate

1. Create project: > django-admin startproject {{project_name}}
2. Create an apps folder inside main project folder
3. Create __init__.py and add to apps folder **Note it will have no code in it.
4. Create the app. You must be in your apps folder:
> python ../manage.py startapp {{app_name}} **Note that you cannot name it the same as the project or you will get an error.
5. Create urls.py and import:

from django.conf.urls import url
from . import views

urlpatterns = [
url(r'^$', views.index),
url(r'^add_word$', views.add_word), #this will differ depending on your method
url(r'^clear$', views.clear) #this will differ depending on your method
]

6. In the 2nd main folder which is siblings with apps, open your urls.py file. Include the following:

from django.conf.urls import url, include
from django.contrib import admin

urlpatterns = [
url(r'^', include('apps.{{app_name}}.urls')),
url(r'^{{app_name}}/', include('apps.{{app_name}}.urls')),
]

7. Create views.py and import libraries:

from django.shortcuts import render, HttpResponse, redirect

8. Create a templates folder and a static folder in your {{app_name}} folder.
9. Inside templates and static, create {{app_name}} folder
10. Inside templates/{{app_name}} create index.html and other templates files - Include {% csrf_token %} in html
11. Inside static/{{app_name}} create CSS folder, images folder, and javascript folder
12. When using sessions, run the following code from the terminal in your project folder:
> python manage.py makemigrations
> python manage.py migrate

13. In the second main folder (sibling to apps) open the settings.py file and add your app to the list of apps using the following syntax:
'apps.{{app_name}}', **Place it at the top of the list and do not forget the comma or you will get an error
14. In the apps urls.py folder, make sure you add a url for each view in the patterns such as:
url(r'^add_word$', views.add_word) **Note, remember to use commas to separate the urls.


request.session**
**'DONT FORGET COMMAS IN SETTINGS.PY'
**'DONT FORGET TO MIGRATE'

111111. Shell Command 11111111.
NameError: name 'Ninjas' is not defined
solution: from apps.app_name.models import *
Binary file added j_chris_miller_python/Django/amadon.zip
Binary file not shown.
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions j_chris_miller_python/Django/main/apps/amadon/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
7 changes: 7 additions & 0 deletions j_chris_miller_python/Django/main/apps/amadon/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from __future__ import unicode_literals

from django.apps import AppConfig


class AmadonConfig(AppConfig):
name = 'amadon'
Empty file.
5 changes: 5 additions & 0 deletions j_chris_miller_python/Django/main/apps/amadon/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from __future__ import unicode_literals

from django.db import models

# Create your models here.
22 changes: 22 additions & 0 deletions j_chris_miller_python/Django/main/apps/amadon/products.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
items=[
{
"id": 1,
"name": "Dojo T-Shirt",
"price": 19.99
},
{
"id": 2,
"name": "Dojo Sweater",
"price": 29.99
},
{
"id": 3,
"name": "Dojo Cup",
"price": 4.99
},
{
"id": 4,
"name": "Algorithm Book",
"price": 49.99
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
body{
/* background-color: green;*/
}

table{
text-align: left;
}
td{
text-align: left;
padding-left: 10px;
}
th{
text-align: left;
padding-left: 10px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html>
<head>
<title>Amazon Checkout</title>
</head>
<body>
<h1>Thank you for your business!</h1>
<p>We charged your credit card for {{ request.session.last_transaction }}
</p>
<p>
You have ordered {{ request.session.total_items }} items so far and spent {{ request.session.total_charged }} with Amadon.com!
</p>
<p><a href="/">Go Back</a></p>

</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html>
<head>
<title>Amadon</title>
<meta charset="utf-8">
{% load static %}
<link rel="stylesheet" type="text/css" href="{% static 'amadon/css/style.css' %}">
</head>
<body>
<div id = "wrapper">
<h1>Amadon Store!</h1>
<table>
<thead>
<tr>
<th>Item</th>
<th>Price</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for item in items %}
<tr>
<td>{{ item.name }}</td>
<td>{{ item.price }}</td>
<td>
<form action = '/buy/{{ item.id }}' method = 'POST'>
{% csrf_token %}
<select name = "quantity">
<option>1</option>
<option>2</option>
<option>3</option>
</select>
<button type="submit">Buy!</button>
</form>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</form>
</div>
</body>
</html>
3 changes: 3 additions & 0 deletions j_chris_miller_python/Django/main/apps/amadon/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.
8 changes: 8 additions & 0 deletions j_chris_miller_python/Django/main/apps/amadon/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.conf.urls import url, include
from . import views

urlpatterns = [
url(r'^$', views.index),
url(r'^buy/(?P<item_id>\d+)', views.buy),
url(r'^checkout', views.checkout)
]
41 changes: 41 additions & 0 deletions j_chris_miller_python/Django/main/apps/amadon/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from __future__ import unicode_literals
from django.shortcuts import render, HttpResponse, redirect
from datetime import datetime
from products import items


def index(request):
if "last_transaction" in request.session.keys():
del request.session['last_transaction']

context = {
"items": items
}

return render(request, 'amadon/index.html', context)

def buy(request, item_id):
#find item in our items list from the url's item_id matching the 'id' key on the item
for item in items:
if item['id'] == int(item_id):
amount_charged = item['price'] * int(request.POST['quantity'])

#exception handler for keys if they don't exist yet
try:
request.session['total_charged']
except KeyError:
request.session['total_charged'] = 0

try:
request.session['total_items']
except KeyError:
request.session['total_items'] = 0

request.session['total_charged'] += amount_charged
request.session['total_items'] += int(request.POST['quantity'])
request.session['last_transaction'] = amount_charged
return redirect('/checkout')

def checkout(request):
return render(request, 'amadon/checkout.html')

Empty file.
3 changes: 3 additions & 0 deletions j_chris_miller_python/Django/main/apps/blogs/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
7 changes: 7 additions & 0 deletions j_chris_miller_python/Django/main/apps/blogs/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from __future__ import unicode_literals

from django.apps import AppConfig


class BlogsConfig(AppConfig):
name = 'blogs'
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2017-12-12 15:19
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='User',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('first_name', models.CharField(max_length=255)),
('last_name', models.CharField(max_length=255)),
('email_address', models.CharField(max_length=255)),
('age', models.IntegerField()),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
],
),
]
Empty file.
12 changes: 12 additions & 0 deletions j_chris_miller_python/Django/main/apps/blogs/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from __future__ import unicode_literals

from django.db import models

class User(models.Model):
first_name = models.CharField(max_length = 255)
last_name = models.CharField(max_length = 255)
email_address = models.CharField(max_length = 255)
age = models.IntegerField()
created_at = models.DateTimeField(auto_now_add = True)
updated_at = models.DateTimeField(auto_now = True)

3 changes: 3 additions & 0 deletions j_chris_miller_python/Django/main/apps/blogs/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 j_chris_miller_python/Django/main/apps/blogs/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.
Empty file.
3 changes: 3 additions & 0 deletions j_chris_miller_python/Django/main/apps/book_authors/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
7 changes: 7 additions & 0 deletions j_chris_miller_python/Django/main/apps/book_authors/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from __future__ import unicode_literals

from django.apps import AppConfig


class BookAuthorsConfig(AppConfig):
name = 'book_authors'
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2017-12-13 14:02
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Author',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('first_name', models.CharField(max_length=255)),
('last_name', models.CharField(max_length=255)),
('email', models.CharField(max_length=255)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
],
),
migrations.CreateModel(
name='Book',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('desc', models.TextField()),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
],
),
migrations.AddField(
model_name='author',
name='books',
field=models.ManyToManyField(related_name='authors', to='book_authors.Book'),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2017-12-13 14:15
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('book_authors', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='author',
name='notes',
field=models.TextField(default=''),
),
migrations.AlterField(
model_name='book',
name='desc',
field=models.TextField(default=''),
),
]
Loading