Skip to content

Commit 98f7570

Browse files
committed
Adding all Scholl app files
0 parents  commit 98f7570

33 files changed

+441
-0
lines changed

advcbv/__init__.py

Whitespace-only changes.
217 Bytes
Binary file not shown.
2.32 KB
Binary file not shown.
1.12 KB
Binary file not shown.
618 Bytes
Binary file not shown.

advcbv/settings.py

+121
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 2.1.7.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/2.1/topics/settings/
8+
9+
For the full list of settings and their values, see
10+
https://docs.djangoproject.com/en/2.1/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/2.1/howto/deployment/checklist/
21+
22+
# SECURITY WARNING: keep the secret key used in production secret!
23+
SECRET_KEY = 'hrmlp^nb8_$2yt2ckllx!zjpqjwt7fhed+vll9dwe9^qdz!hpx'
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/2.1/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/2.1/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/2.1/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/2.1/howto/static-files/
120+
121+
STATIC_URL = '/static/'

advcbv/urls.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""advcbv URL Configuration
2+
3+
The `urlpatterns` list routes URLs to views. For more information please see:
4+
https://docs.djangoproject.com/en/2.1/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: path('', 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: path('', Home.as_view(), name='home')
12+
Including another URLconf
13+
1. Import the include() function: from django.urls import include, path
14+
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
15+
"""
16+
from django.contrib import admin
17+
from django.urls import path, include
18+
from basic_app import views
19+
20+
urlpatterns = [
21+
path('admin/', admin.site.urls),
22+
path('',views.CBview.as_view(),name='base'),
23+
path('basic_app/',include('basic_app.urls')),
24+
]

advcbv/wsgi.py

+16
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/2.1/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()

basic_app/__init__.py

Whitespace-only changes.
220 Bytes
Binary file not shown.
370 Bytes
Binary file not shown.
1.25 KB
Binary file not shown.
634 Bytes
Binary file not shown.
1.77 KB
Binary file not shown.

basic_app/admin.py

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.contrib import admin
2+
from basic_app.models import Student, School
3+
4+
admin.site.register(School)
5+
admin.site.register(Student)

basic_app/apps.py

+5
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'

basic_app/migrations/0001_initial.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Generated by Django 2.1.7 on 2019-04-03 11:00
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
initial = True
9+
10+
dependencies = [
11+
]
12+
13+
operations = [
14+
migrations.CreateModel(
15+
name='School',
16+
fields=[
17+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
18+
('name', models.CharField(max_length=256)),
19+
('principal', models.CharField(max_length=256)),
20+
('location', models.CharField(max_length=256)),
21+
],
22+
),
23+
migrations.CreateModel(
24+
name='Student',
25+
fields=[
26+
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
27+
('name', models.CharField(max_length=256)),
28+
('age', models.PositiveIntegerField()),
29+
('school', models.ForeignKey(on_delete='models.DO_NOTHING', related_name='students', to='basic_app.School')),
30+
],
31+
),
32+
]

basic_app/migrations/__init__.py

Whitespace-only changes.
Binary file not shown.
Binary file not shown.

basic_app/models.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from django.db import models
2+
from django.urls import reverse
3+
4+
class School(models.Model):
5+
name = models.CharField(max_length=256)
6+
principal = models.CharField(max_length=256)
7+
location = models.CharField(max_length=256)
8+
9+
def __str__(self):
10+
return self.name
11+
12+
def get_absolute_url(self):
13+
return reverse("basic_app:detail",kwargs={'pk':self.pk})
14+
15+
class Student(models.Model):
16+
name = models.CharField(max_length=256)
17+
age = models.PositiveIntegerField()
18+
school = models.ForeignKey(School,related_name="students", on_delete="models.DO_NOTHING")
19+
20+
def __str__(self):
21+
return self.name
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!DOCTYPE html>
2+
<html lang="en" dir="ltr">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Base</title>
6+
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
7+
8+
</head>
9+
<body>
10+
11+
<nav class="navbar navbar-default navbar-static-top">
12+
<ul class="nav navbar-nav">
13+
<li> <a class="navbar-brand" href="{% url 'basic_app:list' %}">School</a> </li>
14+
<li> <a class="navbar-link" href="{% url 'admin:index' %}">Admin</a></li>
15+
<li><a class="navbar-link" href="{% url 'base' %}">Home</a></li>
16+
</ul>
17+
18+
</nav>
19+
20+
<div class="container">
21+
{% block body_block %}
22+
{% endblock %}
23+
</div>
24+
</body>
25+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{% extends 'basic_app/basic_app_base.html' %}
2+
{% block body_block %}
3+
4+
<div class="container">
5+
<div class="jumbotron">
6+
7+
<h1>Delete {{school.name}}?</h1> <hr><br><br><br><br>
8+
<form method="post">
9+
{% csrf_token %}
10+
<input type="submit" class="btn btn-primary" value="Submit">
11+
<a href="{% url 'basic_app:detail' pk=school.pk %}">Cancel</a>
12+
</form>
13+
</div>
14+
</div>
15+
16+
{% endblock %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{% extends 'basic_app/basic_app_base.html' %}
2+
3+
{% block body_block %}
4+
<div class="jumbotron">
5+
<h1>Welcom to the school detail page</h1>
6+
<h2>School details:</h2>
7+
<p><label for="">Name:</label> {{ school_detail.name }}</p>
8+
<p><label for="">Principal:</label> {{ school_detail.principal }}</p>
9+
<p><label for="">Location:</label> {{ school_detail.location }}</p>
10+
11+
<h3>Students: </h3>
12+
{% if school_detail.students.all %}
13+
{% for student in school_detail.students.all %}
14+
<p>{{student.name}} who is {{student.age}} years old.</p>
15+
{% endfor %}
16+
{% else %}
17+
<p>Students are not available in this school</p>
18+
{% endif %}
19+
</div>
20+
21+
<div class="container">
22+
23+
<a class="btn btn-warning" href="{% url 'basic_app:update' pk=school_detail.pk %}">Update</a>
24+
<a class="btn btn-danger" href="{% url 'basic_app:delete' pk=school_detail.pk %}">Delete</a>
25+
26+
</div>
27+
<style type="text/css">
28+
label{
29+
font-weight:bold;
30+
}
31+
32+
</style>
33+
{% 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+
5+
<h1>
6+
{% if not form.instance.pk %}
7+
Create School
8+
{% else %}
9+
Update School
10+
{% endif %}
11+
</h1>
12+
13+
<form method="post">
14+
{% csrf_token %}
15+
{{ form.as_p }}
16+
<input type="submit" class="btn btn-primary" value="Submit">
17+
</form>
18+
19+
{% endblock %}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{% extends "basic_app/basic_app_base.html" %}
2+
3+
{% block body_block %}
4+
<h1>Welcome to a list of all schools</h1>
5+
<ol>
6+
{% for school in schools %}
7+
<h2><li><a href="{{ school.id }}">{{school.name}}</a></li></h2>
8+
{% endfor %}
9+
</ol>
10+
{% endblock %}

basic_app/tests.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

basic_app/urls.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from django.urls import path
2+
from basic_app import views
3+
4+
app_name = 'basic_app'
5+
6+
urlpatterns = [
7+
path('',views.SchoolListView.as_view(),name='list'),
8+
path('<int:pk>/',views.SchoolDetailView.as_view(),name='detail'),
9+
path('create/',views.SchoolCreateView.as_view(),name='create'),
10+
path('update/<int:pk>/',views.SchoolUpdateView.as_view(),name='update'),
11+
path('delete/<int:pk>/',views.SchoolDeleteView.as_view(),name="delete"),
12+
13+
]

0 commit comments

Comments
 (0)