From ad029a71ce32af0ba6c98593563d7ce77e70f49b Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Fri, 19 May 2017 16:22:34 +0530 Subject: Create 3rd tutorial slide --- tutorial_3_django_models/slides.md | 153 +++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 tutorial_3_django_models/slides.md (limited to 'tutorial_3_django_models') diff --git a/tutorial_3_django_models/slides.md b/tutorial_3_django_models/slides.md new file mode 100644 index 0000000..369abed --- /dev/null +++ b/tutorial_3_django_models/slides.md @@ -0,0 +1,153 @@ +Tutorial: Create Django Models +=============================== + +Slide 1: What is a Django Model +-------------------------------------- + + - Every Django app has one or more models + - A Django model is a pythonic representation of a Database Table + - A Model Class represents a database table + - A Model attribute represents a column + - Each model instance is table row + - All django models are stored in a models.py + - models.py represents a Database + +Slide 2: Creating Django Models for Blog app +----------------------------------------------- + + - We will create two tables 'blog' and 'article' + - The blog model will have 3 fields: + - name + - creator + - create_date + - the 'article' model will have 5 fields: + - blog + - title + - create_date + - author + - body + +Demonstration +---------------- + + - Add the following code to */blog/models.py* + + # /blog/models.py + from django.db import models + + + class Blog(models.Model): + name = models.CharField(max_length=120) + created_on = models.DateTimeField('date created') + + + class Article(models.Model): + blog = models.ForeignKey(Blog, on_delete=models.CASCADE) + created_on = models.DateTimeField('date created') + title = models.CharField(max_length=120) + body = models.TextField() + draft = models.BooleanField(default=False) + +Slide 3: What is a database migration +--------------------------------------- + - A database migration is a technique that allows you to update your database, including + - Adding & Removing columns + - Altering columns (& the type of data that they can hold) + - Adding & Removing tables + - Migrations makes such changes easy since; + - No need to rebuild the database for every change + - Avoids loss of data + - Django handles migrations by creating a migration *.py* file + - **Demonstrate** + - Run python manage.py --help + - Show the help text for *makemigrations* command + - Show the help text for *migrate* command + +Demonstration +-------------------- + +- Go to the directory containing *manage.py* file + - Make sure that the environment is active + - Run the command to create database migration files + - *python manage.py makemigrations* + - Run the command to apply these migrations + - *python manage.py migrate* + - Output: + - *Show command line output for makemigrations and migrate* + - Observe that a *db.sqlite3* has been created. + - Check the /blog/migrations/ directory and you will observe that a new file has been created. + +Slide 5: What is Django Admin +------------------------------------------- + + - What is the Django Admin + - The django admin is a feature that provides an interface for users to Create, Read, Update and Delete database entries + +Demonstration: Create a superuser +---------------------------------------------- + - Create a superuser to login to the admin interface + - Run *python manage.py createsuperuser* + - Provide a username + - Provide an email address + - Provide a password and confirm it by entering again + - Output: *Superuser created successfully.* + + +Demonstration: Show the Admin interface +--------------------------------- + - Run the django server with + - *python manage.py runserver* + - Open the web browser and go to http://127.0.0.1:8000/admin/ + - You will see the login screen + - [Add Screenshot] + - Enter the superuser credentials as created previously + - You can see the interface + - [Add Screenshot] + +Demonstration: Make the Blog App modifiable through Admin +------------------------------------------- + - In order to display the Blog app and it's components in the admin interface, change the */blog/admin.py* file; + + # /blog/admin.py + from django.contrib import admin + + from .models import Blog, Article + + admin.site.register(Blog) + admin.site.register(Article) + + - Save and exit + - Return to the directory with *manage.py* file + - Run the django server + - *python manage.py runserver* + - Open the web browser and go to http://127.0.0.1:8000/admin/ + - Login to the Admin interface + +Demonstration: Add a Blog database entry +----------------------- + - Click on 'Blog' + - Click on 'Add Blog' + - Fill the form for new blog + - name + - creator + - create_date + - Click on Save + + - You will see your new blog in the list + - You can click on the blog name to view it's details + - Click on Home (in breadcrumb section) + +Demonstration: Add an Article database entry +-------------------------------- + - Click on 'Article' + - Click on 'Add Article' + - Fill the form for the new Article + - blog: Select 'My New Blog' from list + - title + - create_date + - author: Select super-username form the list + - body: Add Article text + - You will see your new article in the list + - You can click on the article name to view it's details + - Click on Save + -- cgit From 09c000f5c51ef6e418f917dcf582ece0a057bf34 Mon Sep 17 00:00:00 2001 From: King Date: Fri, 19 May 2017 18:47:43 +0530 Subject: Update slides.md --- tutorial_3_django_models/slides.md | 106 ++++++++++++++++++++++++------------- 1 file changed, 69 insertions(+), 37 deletions(-) (limited to 'tutorial_3_django_models') diff --git a/tutorial_3_django_models/slides.md b/tutorial_3_django_models/slides.md index 369abed..012a8be 100644 --- a/tutorial_3_django_models/slides.md +++ b/tutorial_3_django_models/slides.md @@ -1,7 +1,39 @@ Tutorial: Create Django Models =============================== -Slide 1: What is a Django Model +Slide 1 [00:08 | 00:08] +------------- +Title Slide: ** Creating Django Models ** + +Slide 2 [00:13 | 00:21] +-------------- + +**Learning Objectives** + +In this tutorial, we will learn to; + - Create a django model + - Database migration + - Use Admin app + +Slide 3 [00:13 | 00:34] +--------------- + +**System Requirements** + - Ubuntu 16.10 + - Python 3.5 or higher version + - python3.4-venv + +Slide 4 [00:15 | 00:49] +--------------- + +**Pre-requisites** + +In order to follow this tutorial, you need to know; + - how to create a django project + - If not, see the relevant django tutorial on http://spoken-tutorial.org + + +Slide 4: What is a Django Model [00:30 | 01:19] -------------------------------------- - Every Django app has one or more models @@ -12,7 +44,7 @@ Slide 1: What is a Django Model - All django models are stored in a models.py - models.py represents a Database -Slide 2: Creating Django Models for Blog app +Slide 5: Creating Django Models for Blog app [00:35 | 01:54] ----------------------------------------------- - We will create two tables 'blog' and 'article' @@ -27,28 +59,29 @@ Slide 2: Creating Django Models for Blog app - author - body -Demonstration +Demonstration [03:00 | 04:54] ---------------- - - Add the following code to */blog/models.py* + - open */blog/models.py* in editor + - Type the following code - # /blog/models.py - from django.db import models + from django.db import models + class Blog(models.Model): + name = models.CharField(max_length=120) + created_on = models.DateTimeField('date created') - class Blog(models.Model): - name = models.CharField(max_length=120) - created_on = models.DateTimeField('date created') + class Article(models.Model): + blog = models.ForeignKey(Blog, on_delete=models.CASCADE) + created_on = models.DateTimeField('date created') + title = models.CharField(max_length=120) + body = models.TextField() + draft = models.BooleanField(default=False) - class Article(models.Model): - blog = models.ForeignKey(Blog, on_delete=models.CASCADE) - created_on = models.DateTimeField('date created') - title = models.CharField(max_length=120) - body = models.TextField() - draft = models.BooleanField(default=False) + - **(Not for narration) Note: For this demonstration there should explanation about each field ** -Slide 3: What is a database migration +Slide 6: What is a database migration [00:45| 05:39] --------------------------------------- - A database migration is a technique that allows you to update your database, including - Adding & Removing columns @@ -56,15 +89,14 @@ Slide 3: What is a database migration - Adding & Removing tables - Migrations makes such changes easy since; - No need to rebuild the database for every change - - Avoids loss of data + - Avoids loss of data - Django handles migrations by creating a migration *.py* file - - **Demonstrate** - - Run python manage.py --help - - Show the help text for *makemigrations* command - - Show the help text for *migrate* command -Demonstration +Demonstration [01:00| 06:39] -------------------- +- Run python manage.py --help + - Show the help text for *makemigrations* command + - Show the help text for *migrate* command - Go to the directory containing *manage.py* file - Make sure that the environment is active @@ -77,13 +109,13 @@ Demonstration - Observe that a *db.sqlite3* has been created. - Check the /blog/migrations/ directory and you will observe that a new file has been created. -Slide 5: What is Django Admin +Slide 5: What is Django Admin App [00:13| 06:52] ------------------------------------------- - - What is the Django Admin - - The django admin is a feature that provides an interface for users to Create, Read, Update and Delete database entries + - What is the Django Admin App + - The django admin app is a feature that provides an interface to Create, Read, Update and Delete model instances -Demonstration: Create a superuser +Demonstration: Create a superuser [00:55| 07:47] ---------------------------------------------- - Create a superuser to login to the admin interface - Run *python manage.py createsuperuser* @@ -93,7 +125,7 @@ Demonstration: Create a superuser - Output: *Superuser created successfully.* -Demonstration: Show the Admin interface +Demonstration: Show the Admin interface [00:45| 08:32] --------------------------------- - Run the django server with - *python manage.py runserver* @@ -104,7 +136,7 @@ Demonstration: Show the Admin interface - You can see the interface - [Add Screenshot] -Demonstration: Make the Blog App modifiable through Admin +Demonstration: Make the Blog App modifiable through Admin [00:45| 08:32] ------------------------------------------- - In order to display the Blog app and it's components in the admin interface, change the */blog/admin.py* file; @@ -115,15 +147,10 @@ Demonstration: Make the Blog App modifiable through Admin admin.site.register(Blog) admin.site.register(Article) - - - Save and exit - - Return to the directory with *manage.py* file - - Run the django server - - *python manage.py runserver* - - Open the web browser and go to http://127.0.0.1:8000/admin/ + - Save - Login to the Admin interface -Demonstration: Add a Blog database entry +Demonstration: Add a Blog database entry [00:40| 09:12] ----------------------- - Click on 'Blog' - Click on 'Add Blog' @@ -137,7 +164,7 @@ Demonstration: Add a Blog database entry - You can click on the blog name to view it's details - Click on Home (in breadcrumb section) -Demonstration: Add an Article database entry +Demonstration: Add an Article database entry [00:45| 09:57] -------------------------------- - Click on 'Article' - Click on 'Add Article' @@ -147,7 +174,12 @@ Demonstration: Add an Article database entry - create_date - author: Select super-username form the list - body: Add Article text + - Click on Save - You will see your new article in the list - You can click on the article name to view it's details - - Click on Save + + *** With this we come to the end of the tutorial*** + ---------------------------------------------------- + *** Add concluding slides and assignment*** + ------------------------------------------- -- cgit From ec25525da6aab2be565d033719f9fa280c2eb1b4 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Fri, 19 May 2017 19:06:28 +0530 Subject: Remove detailed explanation of migrations --- tutorial_3_django_models/slides.md | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'tutorial_3_django_models') diff --git a/tutorial_3_django_models/slides.md b/tutorial_3_django_models/slides.md index 012a8be..6c4e51a 100644 --- a/tutorial_3_django_models/slides.md +++ b/tutorial_3_django_models/slides.md @@ -12,7 +12,7 @@ Slide 2 [00:13 | 00:21] In this tutorial, we will learn to; - Create a django model - - Database migration + - Perform Database migration - Use Admin app Slide 3 [00:13 | 00:34] @@ -81,17 +81,6 @@ Demonstration [03:00 | 04:54] - **(Not for narration) Note: For this demonstration there should explanation about each field ** -Slide 6: What is a database migration [00:45| 05:39] ---------------------------------------- - - A database migration is a technique that allows you to update your database, including - - Adding & Removing columns - - Altering columns (& the type of data that they can hold) - - Adding & Removing tables - - Migrations makes such changes easy since; - - No need to rebuild the database for every change - - Avoids loss of data - - Django handles migrations by creating a migration *.py* file - Demonstration [01:00| 06:39] -------------------- - Run python manage.py --help @@ -108,6 +97,7 @@ Demonstration [01:00| 06:39] - *Show command line output for makemigrations and migrate* - Observe that a *db.sqlite3* has been created. - Check the /blog/migrations/ directory and you will observe that a new file has been created. + - We will be revisiting *migrations* in more detail later Slide 5: What is Django Admin App [00:13| 06:52] ------------------------------------------- -- cgit From 984022a96ab76bafb3419eac2475ad1384798570 Mon Sep 17 00:00:00 2001 From: King Date: Sun, 21 May 2017 11:56:06 +0530 Subject: moved web application framework slides here --- tutorial_3_django_models/slides.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'tutorial_3_django_models') diff --git a/tutorial_3_django_models/slides.md b/tutorial_3_django_models/slides.md index 6c4e51a..e6321fc 100644 --- a/tutorial_3_django_models/slides.md +++ b/tutorial_3_django_models/slides.md @@ -167,6 +167,35 @@ Demonstration: Add an Article database entry [00:45| 09:57] - Click on Save - You will see your new article in the list - You can click on the article name to view it's details + + +So this is a web application framework. +Slide 6 [00:30 | 10:27] +---------------- + +**What is a web application** + +![Block diagram of Web application](https://raw.githubusercontent.com/FOSSEE/learn_django/master/tutorial_1_intro/webapp_diag.png 'Web Application Block diagram') +** Narration for this slide ** + - An application stored on a remote computer i.e. server + - A server can be accessed by a user through a web browser + - The browser communicates with the server by sending a 'request' + - The web application carries out actions as per the request + - It has a 'database' to store and manipulate data + - It sends a 'response' to the user + - The user's browser then displays this response suitably formatted. + +Slide 7 [00:13 | 10:40] +------------------ + +**What is a web Framework** + - Easy to develop web apps + - Provides + - Interface to Database + - Authentication (Login system) + - Templating engine (HTML rendering) + - Forms + *** With this we come to the end of the tutorial*** -- cgit From 8789e0fe4b55ede66ae549f0e804dacbc7c0fcd5 Mon Sep 17 00:00:00 2001 From: King Date: Sun, 21 May 2017 13:39:07 +0530 Subject: modified to show demo percent --- tutorial_3_django_models/slides.md | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'tutorial_3_django_models') diff --git a/tutorial_3_django_models/slides.md b/tutorial_3_django_models/slides.md index e6321fc..bca76bc 100644 --- a/tutorial_3_django_models/slides.md +++ b/tutorial_3_django_models/slides.md @@ -1,11 +1,12 @@ Tutorial: Create Django Models =============================== +[Demonstration time: 9 mins 25 secs (0.785 ~ 79%) | Total time: 12 mins] Slide 1 [00:08 | 00:08] ------------- Title Slide: ** Creating Django Models ** -Slide 2 [00:13 | 00:21] +Slide 2 [00:12 | 00:20] -------------- **Learning Objectives** @@ -15,7 +16,7 @@ In this tutorial, we will learn to; - Perform Database migration - Use Admin app -Slide 3 [00:13 | 00:34] +Slide 3 [00:11 | 00:31] --------------- **System Requirements** @@ -23,7 +24,7 @@ Slide 3 [00:13 | 00:34] - Python 3.5 or higher version - python3.4-venv -Slide 4 [00:15 | 00:49] +Slide 4 [00:11 | 00:42] --------------- **Pre-requisites** @@ -33,7 +34,7 @@ In order to follow this tutorial, you need to know; - If not, see the relevant django tutorial on http://spoken-tutorial.org -Slide 4: What is a Django Model [00:30 | 01:19] +Slide 4: What is a Django Model [00:30 | 01:12] -------------------------------------- - Every Django app has one or more models @@ -44,7 +45,7 @@ Slide 4: What is a Django Model [00:30 | 01:19] - All django models are stored in a models.py - models.py represents a Database -Slide 5: Creating Django Models for Blog app [00:35 | 01:54] +Slide 5: Creating Django Models for Blog app [00:12 | 01:24] ----------------------------------------------- - We will create two tables 'blog' and 'article' @@ -58,8 +59,10 @@ Slide 5: Creating Django Models for Blog app [00:35 | 01:54] - create_date - author - body + + - **(Not for narration) Note: Explain this in detail during demonstration** -Demonstration [03:00 | 04:54] +Demonstration [04:00 | 05:24] ---------------- - open */blog/models.py* in editor @@ -81,7 +84,7 @@ Demonstration [03:00 | 04:54] - **(Not for narration) Note: For this demonstration there should explanation about each field ** -Demonstration [01:00| 06:39] +Demonstration [01:00| 06:24] -------------------- - Run python manage.py --help - Show the help text for *makemigrations* command @@ -99,13 +102,13 @@ Demonstration [01:00| 06:39] - Check the /blog/migrations/ directory and you will observe that a new file has been created. - We will be revisiting *migrations* in more detail later -Slide 5: What is Django Admin App [00:13| 06:52] +Slide 5: What is Django Admin App [00:07| 06:31] ------------------------------------------- - What is the Django Admin App - The django admin app is a feature that provides an interface to Create, Read, Update and Delete model instances -Demonstration: Create a superuser [00:55| 07:47] +Demonstration: Create a superuser [00:55| 07:26] ---------------------------------------------- - Create a superuser to login to the admin interface - Run *python manage.py createsuperuser* @@ -115,7 +118,7 @@ Demonstration: Create a superuser [00:55| 07:47] - Output: *Superuser created successfully.* -Demonstration: Show the Admin interface [00:45| 08:32] +Demonstration: Show the Admin interface [00:45| 08:11] --------------------------------- - Run the django server with - *python manage.py runserver* @@ -126,7 +129,7 @@ Demonstration: Show the Admin interface [00:45| 08:32] - You can see the interface - [Add Screenshot] -Demonstration: Make the Blog App modifiable through Admin [00:45| 08:32] +Demonstration: Make the Blog App modifiable through Admin [01:10 | 09:21] ------------------------------------------- - In order to display the Blog app and it's components in the admin interface, change the */blog/admin.py* file; @@ -140,7 +143,7 @@ Demonstration: Make the Blog App modifiable through Admin [00:45| 08:32] - Save - Login to the Admin interface -Demonstration: Add a Blog database entry [00:40| 09:12] +Demonstration: Add a Blog database entry [00:45| 10:06] ----------------------- - Click on 'Blog' - Click on 'Add Blog' @@ -154,7 +157,7 @@ Demonstration: Add a Blog database entry [00:40| 09:12] - You can click on the blog name to view it's details - Click on Home (in breadcrumb section) -Demonstration: Add an Article database entry [00:45| 09:57] +Demonstration: Add an Article database entry [00:50| 10:56] -------------------------------- - Click on 'Article' - Click on 'Add Article' @@ -170,13 +173,13 @@ Demonstration: Add an Article database entry [00:45| 09:57] So this is a web application framework. -Slide 6 [00:30 | 10:27] +Slide 6 [00:17 | 11:13] ---------------- **What is a web application** ![Block diagram of Web application](https://raw.githubusercontent.com/FOSSEE/learn_django/master/tutorial_1_intro/webapp_diag.png 'Web Application Block diagram') -** Narration for this slide ** +** Can be used for narration for this slide ** - An application stored on a remote computer i.e. server - A server can be accessed by a user through a web browser - The browser communicates with the server by sending a 'request' @@ -185,7 +188,7 @@ Slide 6 [00:30 | 10:27] - It sends a 'response' to the user - The user's browser then displays this response suitably formatted. -Slide 7 [00:13 | 10:40] +Slide 7 [00:05 | 11:18] ------------------ **What is a web Framework** @@ -200,5 +203,5 @@ Slide 7 [00:13 | 10:40] *** With this we come to the end of the tutorial*** ---------------------------------------------------- - *** Add concluding slides and assignment*** + *** Add concluding slides and assignment***[00:42 | 12:00 ] ------------------------------------------- -- cgit From e7e0724b39e45518fbb22371710bc48b74286353 Mon Sep 17 00:00:00 2001 From: ankitjavalkar Date: Wed, 21 Jun 2017 20:07:12 +0530 Subject: Update slides based on PR suggestions --- tutorial_3_django_models/slides.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'tutorial_3_django_models') diff --git a/tutorial_3_django_models/slides.md b/tutorial_3_django_models/slides.md index bca76bc..3e3bdcd 100644 --- a/tutorial_3_django_models/slides.md +++ b/tutorial_3_django_models/slides.md @@ -40,9 +40,9 @@ Slide 4: What is a Django Model [00:30 | 01:12] - Every Django app has one or more models - A Django model is a pythonic representation of a Database Table - A Model Class represents a database table - - A Model attribute represents a column - - Each model instance is table row - - All django models are stored in a models.py + - A Model attribute represents a table field (each column in the table) + - Each model instance is a table record (each row in the table) + - All django models are written in a models.py - models.py represents a Database Slide 5: Creating Django Models for Blog app [00:12 | 01:24] @@ -51,14 +51,13 @@ Slide 5: Creating Django Models for Blog app [00:12 | 01:24] - We will create two tables 'blog' and 'article' - The blog model will have 3 fields: - name - - creator - - create_date + - created_on - the 'article' model will have 5 fields: - blog + - created_on - title - - create_date - - author - body + - draft - **(Not for narration) Note: Explain this in detail during demonstration** @@ -179,7 +178,7 @@ Slide 6 [00:17 | 11:13] **What is a web application** ![Block diagram of Web application](https://raw.githubusercontent.com/FOSSEE/learn_django/master/tutorial_1_intro/webapp_diag.png 'Web Application Block diagram') -** Can be used for narration for this slide ** +**Can be used for narration for this slide** - An application stored on a remote computer i.e. server - A server can be accessed by a user through a web browser - The browser communicates with the server by sending a 'request' -- cgit