Commits

Nick Efford committed a873141

Updated initial slides and added some on generic views.

Comments (0)

Files changed (1)

slides/slides.tex

   \setlength{\itemsep}{3pt plus 2pt minus 3pt}}%
  {\end{itemize}}
 
+\newcommand{\vsb}[1][1]{\vspace{#1\baselineskip}}
+
 \usepackage{times}
 \usepackage[T1]{fontenc}
 \usepackage{upquote}
 \subsection{Setting Up}
 
 
-\begin{frame}[fragile]{What You Will Need\ldots}
-  \begin{itemize}
-    \item Python 2.6 or 2.7
-    \item Latest Django (1.3 alpha) from Subversion trunk
-      \begin{Verbatim}[gobble=6,fontsize=\relsize{-1}]
-        svn co http://code.djangoproject.com/svn/django/trunk
-      \end{Verbatim}
-    \item Code for this tutorial, from bitbucket:
-      \begin{Verbatim}[gobble=6,fontsize=\relsize{-1}]
-        http://bitbucket.org/pythoneer/ypy-django
-      \end{Verbatim}
-      (|hg| |clone| this or visit in browser to download an archive)
-  \end{itemize}
+\begin{frame}[fragile]{Installing What You Need}
+  \begin{enumerate}
+    \item Create a directory for this tutorial
+    \item Copy |django-admin.py|, |django-example.zip|,
+      |django-trunk.zip| from USB drive to the new directory
+    \item Unpack the two Zip archives
+  \end{enumerate}
   \begin{center}
     \smaller
-    \begin{minipage}{0.8\textwidth}
-      \begin{alertblock}<visible@2->{Alternatively}
-        Borrow a CD and copy the Django \& tutorial directories from it \ldots
+    \begin{minipage}{0.75\textwidth}
+      \begin{alertblock}<visible@2->{Windows Users}
+        \textbf{Avoid spaces in pathnames!}
+        \par\vsb[0.5]
+        Try putting Django \& the example project in |C:\tmp| or similar
+      \end{alertblock}
+    \end{minipage}
+  \end{center}
+  \begin{center}
+    \smaller
+    \begin{minipage}{0.75\textwidth}
+      \begin{alertblock}<visible@3->{Note}
+        We assume you have Python 2.6 or 2.7 already installed \ldots
       \end{alertblock}
     \end{minipage}
   \end{center}
 \end{frame}
 
-\begin{frame}[fragile]{Setting Up Django For This Tutorial}
-  Do \emph{one} of these:
+\begin{frame}[fragile]{Setting Up Django}
+  Do \emph{one} of the following:
   \begin{itemize}
-    \item Go to main directory (the one containing |README|) and do
+    \item In |django-trunk| directory (the one containing |README|) do
       \begin{Verbatim}[gobble=6]
         python setup.py install
       \end{Verbatim}
-    \item Set |PYTHONPATH| to include main directory
+    \item Set |PYTHONPATH| to include |django-trunk| directory
   \end{itemize}
-  \vspace{0.5\baselineskip}
+  \vsb[0.5]
   Use Python interpreter to verify:
   \begin{Verbatim}[gobble=2]
     >>> import django
     >>> django.VERSION
     (1, 3, 0, 'alpha', 1)
   \end{Verbatim}
-  \begin{center}
-    \smaller
-    \begin{minipage}{0.75\textwidth}
-      \begin{alertblock}<visible@2->{Windows Users}
-        \textbf{Avoid spaces in pathnames!}
-        \par\vspace{0.5\baselineskip}
-        Try putting Django and tutorial code in |C:\tmp| or similar \ldots
-      \end{alertblock}
-    \end{minipage}
-  \end{center}
 \end{frame}
 
 
       \item Contains or references one or more \textbf{apps}
     \end{itemize}
   \end{uncoverenv}
-  \vspace{\baselineskip}
+  \vsb
   \begin{uncoverenv}<2->
     \textbf{App}
     \begin{itemize}
     django-admin.py startproject football
   \end{LVerbatim}
 
-  \vspace{\baselineskip}
+  \vsb
   Creating an app within a project directory:
 
   \begin{LVerbatim}[gobble=4]
     \item Paths to templates and static media
     \item How logging is done \ldots
   \end{itemize}
-  \vspace{0.5\baselineskip}
+  \vsb[0.5]
   \begin{visibleenv}<2->
   \begin{Verbatim}[gobble=2,frame=single,fontsize=\relsize{-2}]
   DATABASES = {
 
 \begin{frame}[fragile]{The Data Model}
   \begin{itemize}
-    \item A way of describing database layout in Python code (a class)
-    \item Normally represents a single database table
-    \item Has \textbf{fields} that map onto columns of that table
-    \item Many built-in field types (also classes)
+    \item A description of database layout, as a Python class
+    \item Normally represents one database table
+    \item Has \textbf{fields} that map onto columns of the table
+    \item Many built-in field types
       \begin{itemize2}
         \item |CharField|, |TextField|
         \item |IntegerField|, |FloatField|, |DecimalField|
 
 \begin{frame}[fragile]{Creating \& Saving Objects}
   Invoke constructor and call |save| method:
+  \vsb[0.25]
   \begin{Verbatim}[gobble=4,frame=single,fontsize=\relsize{-1}]
     club = Club(name='Arsenal', year_established=1886,
                 ground='Emirates Stadium')
 
     club.save()
   \end{Verbatim}
-  \vspace{0.5\baselineskip}
+  \vsb
   \ldots or call |create| method of |Club| model manager:
+  \vsb[0.25]
   \begin{Verbatim}[gobble=4,frame=single,fontsize=\relsize{-1}]
     Club.objects.create(name='Arsenal', year_established=1886,
                         ground='Emirates Stadium')
 
 \begin{frame}[fragile]{Retrieving Objects}
   Retrieve a single object with |get|:
+  \vsb[0.25]
   \begin{Verbatim}[gobble=4,frame=single,fontsize=\relsize{-1}]
     club = Club.objects.get(name='Liverpool')
   \end{Verbatim}
-  \vspace{0.5\baselineskip}
+  \vsb
   Retrieve \textbf{querysets} with |all|, |filter|, etc:
+  \vsb[0.25]
   \begin{Verbatim}[gobble=4,frame=single,fontsize=\relsize{-1}]
     for club in Club.objects.all():
         print club
 
     admin.site.register(Club)
   \end{Verbatim}
-  \vspace{0.5\baselineskip}
+  \vsb[0.5]
   In top-level |urls.py|:
   \begin{Verbatim}[gobble=4,frame=single,fontsize=\relsize{-1}]
     from django.contrib import admin
 
 
 \begin{frame}{Generic Views}
+  Provide ready-made logic for many common tasks:
+  \begin{itemize}
+    \item Issuing a redirect
+    \item Displaying a list of objects
+    \item Displaying a \lq detail' page for a single object
+    \item Yearly, monthly or daily archiving of date-based objects
+    \item lq Latest items' page for date-based objects
+    \item Object creation, updating, deletion (with/without authorisation)
+  \end{itemize}
+\end{frame}
+
+
+\begin{frame}[fragile]{Generic Views Example}
+  |views.py|
+  \begin{Verbatim}[gobble=4,frame=single,fontsize=\relsize{-1}]
+    from django.views.generic import ListView
+    from football.club.models import Club
+
+    class ClubListView(ListView):
+        model = Club
+        context_object_name = 'clubs'
+  \end{Verbatim}
+  \vsb[0.25]
+  \begin{visibleenv}<2->
+  |urls.py|
+  \begin{Verbatim}[gobble=4,frame=single,fontsize=\relsize{-1}]
+    from django.conf.urls.defaults import *
+    from football.club.views import ClubListView
+
+    urlpatterns = patterns('',
+      (r'^$', ClubListView.as_view()),
+      ...
+    )
+  \end{Verbatim}
+  \end{visibleenv}
 \end{frame}
 
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.