summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorprathamesh2018-03-22 10:44:00 +0530
committerprathamesh2018-03-22 10:44:00 +0530
commit20005d5c2da05ed960681a5a2bdffe5410525e25 (patch)
treea5d9214581105b3847eef1f6b5ebb60e2a955af3
parentada3a7315e182474e365b23438713fb290af7c97 (diff)
parent10819ce74ef113b65280f587ba231061b6fdae29 (diff)
downloadlearn_django-20005d5c2da05ed960681a5a2bdffe5410525e25.tar.gz
learn_django-20005d5c2da05ed960681a5a2bdffe5410525e25.tar.bz2
learn_django-20005d5c2da05ed960681a5a2bdffe5410525e25.zip
Merge branch 'master' into tutorial5
-rw-r--r--tutorial_1_intro/slide_1.md1
-rw-r--r--tutorial_2_installation/slides.md54
-rw-r--r--tutorial_3_django_models/slides.md206
-rw-r--r--tutorial_4_django_views_templates/slides.md130
4 files changed, 337 insertions, 54 deletions
diff --git a/tutorial_1_intro/slide_1.md b/tutorial_1_intro/slide_1.md
index 3f2231a..8b187ec 100644
--- a/tutorial_1_intro/slide_1.md
+++ b/tutorial_1_intro/slide_1.md
@@ -87,6 +87,7 @@ Slide 10 [00:12 | 01:27]
---------------
**What is a virtual environment**
+
- Create 'isolated' environment
- Does not require root access
- Install Python packages from PyPI
diff --git a/tutorial_2_installation/slides.md b/tutorial_2_installation/slides.md
deleted file mode 100644
index 874204c..0000000
--- a/tutorial_2_installation/slides.md
+++ /dev/null
@@ -1,54 +0,0 @@
-Tutorial 2: Installation
-============================
-
-Slide 1
----------------
-
-**System Requirements:**
- - Python 3
- - python3.4-venv (Install using *apt-get install python3.4-venv*)
- - Ubuntu 16.10
-
-Slide 2
----------------
-
-**What is virtual environment**
- - Install Python packages from PyPI
- - Does not require root access
- - Create 'isolated' environment
-
-Slide 3
-----------------
-
-**Working with virtual environments**
- - Create a virtual environment
- - python -m venv /path-to-env/directory_name
- - Activate the environment
- - source /path-to-env/bin/activate
- - Deactivate the environment
- - deactivate
- - Delete the environment and related packages
- - Delete the environment directory
-
-
-Slide 4
----------------
-
-**Create a virtual environment**
- - Creating a virtual environment in Python 3
- - *python3 -m venv /path-to-env/myapp_env*
-
-Slide 5
-----------------
-
-**Activate the virtual environment**
- - *source /path-to-env/myapp_env*
- - Shell prompt will be *(myapp_env)user1:~$*
-
-Slide 5
----------------
-
-**Install Django**
- - pip install django
- - Check if django is installed using;
- - Command: *python -m django --version*
diff --git a/tutorial_3_django_models/slides.md b/tutorial_3_django_models/slides.md
new file mode 100644
index 0000000..3e3bdcd
--- /dev/null
+++ b/tutorial_3_django_models/slides.md
@@ -0,0 +1,206 @@
+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:12 | 00:20]
+--------------
+
+**Learning Objectives**
+
+In this tutorial, we will learn to;
+ - Create a django model
+ - Perform Database migration
+ - Use Admin app
+
+Slide 3 [00:11 | 00:31]
+---------------
+
+**System Requirements**
+ - Ubuntu 16.10
+ - Python 3.5 or higher version
+ - python3.4-venv
+
+Slide 4 [00:11 | 00:42]
+---------------
+
+**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: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 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]
+-----------------------------------------------
+
+ - We will create two tables 'blog' and 'article'
+ - The blog model will have 3 fields:
+ - name
+ - created_on
+ - the 'article' model will have 5 fields:
+ - blog
+ - created_on
+ - title
+ - body
+ - draft
+
+ - **(Not for narration) Note: Explain this in detail during demonstration**
+
+Demonstration [04:00 | 05:24]
+----------------
+
+ - open */blog/models.py* in editor
+ - Type the following code
+
+ 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)
+
+ - **(Not for narration) Note: For this demonstration there should explanation about each field **
+
+Demonstration [01:00| 06:24]
+--------------------
+- 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
+ - 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.
+ - We will be revisiting *migrations* in more detail later
+
+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:26]
+----------------------------------------------
+ - 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 [00:45| 08:11]
+---------------------------------
+ - 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 [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;
+
+ # /blog/admin.py
+ from django.contrib import admin
+
+ from .models import Blog, Article
+
+ admin.site.register(Blog)
+ admin.site.register(Article)
+ - Save
+ - Login to the Admin interface
+
+Demonstration: Add a Blog database entry [00:45| 10:06]
+-----------------------
+ - 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 [00:50| 10:56]
+--------------------------------
+ - 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
+ - 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: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**
+ - 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:05 | 11:18]
+------------------
+
+**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***
+ ----------------------------------------------------
+ *** Add concluding slides and assignment***[00:42 | 12:00 ]
+ -------------------------------------------
diff --git a/tutorial_4_django_views_templates/slides.md b/tutorial_4_django_views_templates/slides.md
new file mode 100644
index 0000000..8021b50
--- /dev/null
+++ b/tutorial_4_django_views_templates/slides.md
@@ -0,0 +1,130 @@
+Tutorial: Create Views and Route your URLs
+===========================================
+[Demonstration time: 7 mins 00 s (0.817 ~ 82%) | Total time: 8 mins 34 s]
+
+Slide 1 [00:08 | 00:08]
+------------
+Title Slide
+**Creating Views and Resolving URLs**
+
+Slide 2 [00:12 | 00:20]
+--------------
+
+**Learning Objectives**
+
+In this tutorial, we will learn to:
+ - Create a django view
+ - Create a url routing scheme
+
+Slide 3 [00:11 | 00:31]
+---------------
+
+**System Requirements**
+ - Ubuntu 16.10
+ - Python 3.5 or higher version
+ - python3.4-venv
+
+Slide 4 [00:11 | 00:42]
+---------------
+
+**Pre-requisites**
+
+In order to follow this tutorial, you need to know:
+ - how to create models in django
+ - If not, see the relevant django tutorial on http://spoken-tutorial.org
+
+Slide 5 [00:10 | 00:52]
+------------
+**What is a View**
+ - A view is code that accepts a request
+ - It processes the request and sends back a response
+
+Demonstration [02:00 | 02:52]
+-----------
+**Creating a View**
+
+Edit the /blog/views.py
+
+ # /blog/views.py
+ from django.http import HttpResponse
+
+ from .models import Blog
+
+ def get_blogs(request):
+ blogs = Blog.objects.all() # This is called a query
+ return HttpResponse(blogs)
+
+ - Narrator Notes: Please state that Django queries will be explained later in the series,
+ and should explain the above code.
+
+Demonstration [02:50 | 05:42]
+-----------
+**Add URL routing to URLConf**
+
+Now change the /myproject/urls.py so that the project knows which urls file to call
+
+This is called the URL Dispatcher
+
+ # /myproject/urls.py
+ from django.conf.urls import include, url
+ from django.contrib import admin
+ from blog import views
+
+ urlpatterns = [
+ url(r'^admin/', admin.site.urls),
+ url(r'^blogs/$', views.get_blogs, name='blogs') # Add this line
+ ]
+
+ - Run the django server using command:
+ - python manage.py runserver
+
+ - **Narrator Note**: Show the web browser to the user
+ - Go to the url http://localhost:8000/blogs/ and show the output.
+ - You will see the blog object Query set.
+ - So we have created a simple client-server model.(At this point we can show
+ the image, we showed in the previous tutorial.)
+ - Let us now improve our view.
+
+
+Demonstration [01:30 | 06:22]
+-----------
+In the /blog/views.py edit get_blogs function
+
+
+ def get_blogs(request):
+ blogs = Blog.objects.all() # This is called a query
+ response = 'Blogs:\n\n'
+ for blog in blogs:
+ response += '{0}\n'.format(blog)
+ return HttpResponse(response)
+
+ - Narrator Notes: Should explain the above code.
+ - Save and again show the browser.
+ - We now see the individual blog object created in tutorial 3.
+
+
+Demonstration [01:30 | 07:52]
+-----------
+Let us further edit the view to display articles related to a blog.
+In the /blog/views.py edit get_blogs function
+
+
+ def get_blogs(request):
+ blogs = Blog.objects.all() # This is called a query
+ response = 'Blogs:\n\n'
+ for blog in blogs:
+ articles = Articles.objects.filter(blog=blog)
+ response += '{0}\n'.format(blog)
+ response += '\n'.join([article.title for article in articles])
+ return HttpResponse(response)
+
+ - Narrator Notes: Should explain the above code.
+ - Save and again show the browser.
+ - We now also see the article created in the tutorial 3.
+
+
+*** With this we come to the end of the tutorial***
+ ----------------------------------------------------
+*** Add concluding slides and assignment***[00:42 | 08:34]
+ -------------------------------------------
+ Narrator Notes: Can give assignment to create a view ***count_blogs*** for displaying the number of blogs.