Skip to content

Commit 679922e

Browse files
committed
Added Section 1 of he course
1 parent 2318ae7 commit 679922e

File tree

998 files changed

+25591
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

998 files changed

+25591
-0
lines changed

Section 1 - Course Introduction/DJANGO_COURSE_1.xx/Advanced_Django_CBV/advcbv/advcbv/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
"""
2+
Django settings for advcbv project.
3+
4+
Generated by 'django-admin startproject' using Django 1.10.5.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/1.10/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/1.10/ref/settings/
11+
"""
12+
13+
import os
14+
15+
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
16+
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
17+
TEMPLATE_DIR = os.path.join(BASE_DIR,'templates')
18+
19+
# Quick-start development settings - unsuitable for production
20+
# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/
21+
22+
# SECURITY WARNING: keep the secret key used in production secret!
23+
SECRET_KEY = '7!6cfh24dtp$9dcxm2m_yj%a-riev0&_ma@51_om_umo=+^5fi'
24+
25+
# SECURITY WARNING: don't run with debug turned on in production!
26+
DEBUG = True
27+
28+
ALLOWED_HOSTS = []
29+
30+
31+
# Application definition
32+
33+
INSTALLED_APPS = [
34+
'django.contrib.admin',
35+
'django.contrib.auth',
36+
'django.contrib.contenttypes',
37+
'django.contrib.sessions',
38+
'django.contrib.messages',
39+
'django.contrib.staticfiles',
40+
'basic_app',
41+
]
42+
43+
MIDDLEWARE = [
44+
'django.middleware.security.SecurityMiddleware',
45+
'django.contrib.sessions.middleware.SessionMiddleware',
46+
'django.middleware.common.CommonMiddleware',
47+
'django.middleware.csrf.CsrfViewMiddleware',
48+
'django.contrib.auth.middleware.AuthenticationMiddleware',
49+
'django.contrib.messages.middleware.MessageMiddleware',
50+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
51+
]
52+
53+
ROOT_URLCONF = 'advcbv.urls'
54+
55+
TEMPLATES = [
56+
{
57+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
58+
'DIRS': [TEMPLATE_DIR],
59+
'APP_DIRS': True,
60+
'OPTIONS': {
61+
'context_processors': [
62+
'django.template.context_processors.debug',
63+
'django.template.context_processors.request',
64+
'django.contrib.auth.context_processors.auth',
65+
'django.contrib.messages.context_processors.messages',
66+
],
67+
},
68+
},
69+
]
70+
71+
WSGI_APPLICATION = 'advcbv.wsgi.application'
72+
73+
74+
# Database
75+
# https://docs.djangoproject.com/en/1.10/ref/settings/#databases
76+
77+
DATABASES = {
78+
'default': {
79+
'ENGINE': 'django.db.backends.sqlite3',
80+
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
81+
}
82+
}
83+
84+
85+
# Password validation
86+
# https://docs.djangoproject.com/en/1.10/ref/settings/#auth-password-validators
87+
88+
AUTH_PASSWORD_VALIDATORS = [
89+
{
90+
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
91+
},
92+
{
93+
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
94+
},
95+
{
96+
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
97+
},
98+
{
99+
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
100+
},
101+
]
102+
103+
104+
# Internationalization
105+
# https://docs.djangoproject.com/en/1.10/topics/i18n/
106+
107+
LANGUAGE_CODE = 'en-us'
108+
109+
TIME_ZONE = 'UTC'
110+
111+
USE_I18N = True
112+
113+
USE_L10N = True
114+
115+
USE_TZ = True
116+
117+
118+
# Static files (CSS, JavaScript, Images)
119+
# https://docs.djangoproject.com/en/1.10/howto/static-files/
120+
121+
STATIC_URL = '/static/'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""advcbv URL Configuration
2+
3+
The `urlpatterns` list routes URLs to views. For more information please see:
4+
https://docs.djangoproject.com/en/1.10/topics/http/urls/
5+
Examples:
6+
Function views
7+
1. Add an import: from my_app import views
8+
2. Add a URL to urlpatterns: url(r'^$', views.home, name='home')
9+
Class-based views
10+
1. Add an import: from other_app.views import Home
11+
2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home')
12+
Including another URLconf
13+
1. Import the include() function: from django.conf.urls import url, include
14+
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
15+
"""
16+
from django.conf.urls import url,include
17+
from django.contrib import admin
18+
from basic_app import views
19+
20+
urlpatterns = [
21+
url(r'^admin/', admin.site.urls,name='admin'),
22+
url(r'^$',views.IndexView.as_view()),
23+
url(r'^basic_app/',include('basic_app.urls',namespace='basic_app')),
24+
# url(r'^$',views.CBView.as_view()),
25+
# url(r'^$',views.index)
26+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
WSGI config for advcbv project.
3+
4+
It exposes the WSGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/
8+
"""
9+
10+
import os
11+
12+
from django.core.wsgi import get_wsgi_application
13+
14+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "advcbv.settings")
15+
16+
application = get_wsgi_application()

Section 1 - Course Introduction/DJANGO_COURSE_1.xx/Advanced_Django_CBV/advcbv/basic_app/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.contrib import admin
2+
from basic_app.models import School,Student
3+
# Register your models here.
4+
admin.site.register(School)
5+
admin.site.register(Student)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.apps import AppConfig
2+
3+
4+
class BasicAppConfig(AppConfig):
5+
name = 'basic_app'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.10.5 on 2017-03-17 21:38
3+
from __future__ import unicode_literals
4+
5+
from django.conf import settings
6+
from django.db import migrations, models
7+
import django.db.models.deletion
8+
9+
10+
class Migration(migrations.Migration):
11+
12+
initial = True
13+
14+
dependencies = [
15+
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
16+
]
17+
18+
operations = [
19+
migrations.CreateModel(
20+
name='School',
21+
fields=[
22+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
23+
('name', models.CharField(max_length=256)),
24+
('location', models.CharField(max_length=256)),
25+
('principal', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='schools', to=settings.AUTH_USER_MODEL)),
26+
],
27+
),
28+
migrations.CreateModel(
29+
name='Student',
30+
fields=[
31+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
32+
('name', models.CharField(max_length=256)),
33+
('age', models.PositiveIntegerField()),
34+
('school', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='students', to='basic_app.School')),
35+
],
36+
),
37+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# -*- coding: utf-8 -*-
2+
# Generated by Django 1.10.5 on 2017-03-18 00:00
3+
from __future__ import unicode_literals
4+
5+
from django.db import migrations, models
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('basic_app', '0001_initial'),
12+
]
13+
14+
operations = [
15+
migrations.AlterField(
16+
model_name='school',
17+
name='principal',
18+
field=models.CharField(max_length=256),
19+
),
20+
]

Section 1 - Course Introduction/DJANGO_COURSE_1.xx/Advanced_Django_CBV/advcbv/basic_app/migrations/__init__.py

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from django.db import models
2+
from django.core.urlresolvers import reverse
3+
4+
# Create your models here.
5+
class School(models.Model):
6+
name = models.CharField(max_length=256)
7+
principal = models.CharField(max_length=256)
8+
location = models.CharField(max_length=256)
9+
10+
def __str__(self):
11+
return self.name
12+
13+
def get_absolute_url(self):
14+
return reverse("basic_app:detail",kwargs={'pk':self.pk})
15+
16+
class Student(models.Model):
17+
name = models.CharField(max_length=256)
18+
age = models.PositiveIntegerField()
19+
school = models.ForeignKey(School,related_name='students')
20+
21+
def __str__(self):
22+
return self.name
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<!DOCTYPE html>
2+
{% load staticfiles %}
3+
<html>
4+
<head>
5+
<meta charset="utf-8">
6+
<title>
7+
CBVs
8+
{# Title Extensions go inside the block#}
9+
{% block title_block %}
10+
11+
{% endblock %}
12+
</title>
13+
14+
{# Bootstrap and CSS (Probably would want downloaded files in your real projects)#}
15+
{# https://bootswatch.com/#}
16+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
17+
18+
</head>
19+
<body>
20+
<nav class="navbar navbar-default navbar-static-top">
21+
<ul class="nav navbar-nav">
22+
<li><a class="navbar-brand" href="{% url 'basic_app:list' %}">Schools</a></li>
23+
<li><a class="navbar-link" href="{% url 'admin:index' %}">Admin</a></li>
24+
<li><a class="navbar-link" href="{% url 'basic_app:create' %}">Create School</a></li>
25+
</ul>
26+
</nav>
27+
28+
<div class="container">
29+
{% block body_block %}
30+
31+
{% endblock %}
32+
</div>
33+
34+
</body>
35+
36+
{# Plugins#}
37+
38+
39+
<!-- Latest compiled and minified JavaScript -->
40+
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
41+
<script
42+
src="https://code.jquery.com/jquery-3.2.0.min.js"
43+
integrity="sha256-JAW99MJVpJBGcbzEuXk4Az05s/XyDdBomFqNlM3ic+I="
44+
crossorigin="anonymous"></script>
45+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{% extends "basic_app/basic_app_base.html" %}
2+
3+
{% block body_block %}
4+
<h1>Delete {{school.name }}?</h1>
5+
6+
<form method="post">
7+
{% csrf_token %}
8+
<input type="submit" class="btn btn-danger" value="Delete">
9+
<a href="{% url 'basic_app:detail' pk=school.pk%} ">Cancel</a>
10+
11+
</form>
12+
13+
{% endblock %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{% extends "basic_app/basic_app_base.html" %}
2+
{% block body_block %}
3+
<div class="jumbotron">
4+
<h1>Welcome to the School Detail Page</h1>
5+
<h2>School Details:</h2>
6+
<p>Id_num: {{school_details.id}}</p>
7+
<p>Name: {{school_details.name}}</p>
8+
<p>Principal: {{school_details.principal}}</p>
9+
<p>Location: {{school_details.location}}</p>
10+
<h3>Students:</h3>
11+
12+
{% for student in school_details.students.all %}
13+
<p>{{student.name}} who is {{student.age}} years old.</p>
14+
{% endfor %}
15+
16+
</div>
17+
<div class="container">
18+
<p><a class='btn btn-warning' href="{% url 'basic_app:update' pk=school_details.pk %}">Update</a></p>
19+
20+
</div>
21+
22+
{% endblock %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{% extends "basic_app/basic_app_base.html" %}
2+
3+
{% block body_block %}
4+
<h1>
5+
{% if not form.instance.pk %}
6+
Create School
7+
{% else %}
8+
Update School
9+
{% endif %}
10+
</h1>
11+
<form method="POST">
12+
{% csrf_token %}
13+
{{ form.as_p }}
14+
<input type="submit" class='btn btn-primary' value="Submit">
15+
16+
</form>
17+
18+
19+
{% endblock %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{% extends "basic_app/basic_app_base.html" %}
2+
{% block body_block %}
3+
<div class="jumbotron">
4+
5+
<h1>Welcome to the List of Schools Page!</h1>
6+
<ol>
7+
{% for school in school_list %}
8+
<h2><li><a href="{{school.id}}/">{{school.name}} </a></li></h2>
9+
{% endfor %}
10+
</ol>
11+
12+
</div>
13+
14+
15+
{% endblock %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from django.conf.urls import url
2+
from basic_app import views
3+
4+
app_name = 'basic_app'
5+
6+
urlpatterns = [
7+
url(r'^$',views.SchoolListView.as_view(),name='list'),
8+
url(r'^(?P<pk>\d+)/$',views.SchoolDetailView.as_view(),name='detail'),
9+
url(r'^create/$',views.SchoolCreateView.as_view(),name='create'),
10+
url(r'^update/(?P<pk>\d+)/$',views.SchoolUpdateView.as_view(),name='update'),
11+
url(r'^delete/(?P<pk>\d+)/$',views.SchoolDeleteView.as_view(),name='delete')
12+
]

0 commit comments

Comments
 (0)