Nick Efford committed a873141

Updated initial slides and added some on generic views.

Comments (0)

Files changed (1)


   \setlength{\itemsep}{3pt plus 2pt minus 3pt}}%
 \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
-      \end{Verbatim}
-    \item Code for this tutorial, from bitbucket:
-      \begin{Verbatim}[gobble=6,fontsize=\relsize{-1}]
-      \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 ||, ||,
+      || from USB drive to the new directory
+    \item Unpack the two Zip archives
+  \end{enumerate}
-    \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
-\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:
-    \item Go to main directory (the one containing |README|) and do
+    \item In |django-trunk| directory (the one containing |README|) do
         python install
-    \item Set |PYTHONPATH| to include main directory
+    \item Set |PYTHONPATH| to include |django-trunk| directory
-  \vspace{0.5\baselineskip}
+  \vsb[0.5]
   Use Python interpreter to verify:
     >>> import django
     >>> django.VERSION
     (1, 3, 0, 'alpha', 1)
-  \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}
       \item Contains or references one or more \textbf{apps}
-  \vspace{\baselineskip}
+  \vsb
     \begin{itemize} startproject football
-  \vspace{\baselineskip}
+  \vsb
   Creating an app within a project directory:
     \item Paths to templates and static media
     \item How logging is done \ldots
-  \vspace{0.5\baselineskip}
+  \vsb[0.5]
 \begin{frame}[fragile]{The Data Model}
-    \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
         \item |CharField|, |TextField|
         \item |IntegerField|, |FloatField|, |DecimalField|
 \begin{frame}[fragile]{Creating \& Saving Objects}
   Invoke constructor and call |save| method:
+  \vsb[0.25]
     club = Club(name='Arsenal', year_established=1886,
                 ground='Emirates Stadium')
-  \vspace{0.5\baselineskip}
+  \vsb
   \ldots or call |create| method of |Club| model manager:
+  \vsb[0.25]
     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]
     club = Club.objects.get(name='Liverpool')
-  \vspace{0.5\baselineskip}
+  \vsb
   Retrieve \textbf{querysets} with |all|, |filter|, etc:
+  \vsb[0.25]
     for club in Club.objects.all():
         print club
-  \vspace{0.5\baselineskip}
+  \vsb[0.5]
   In top-level ||:
     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}
+\begin{frame}[fragile]{Generic Views Example}
+  ||
+  \begin{Verbatim}[gobble=4,frame=single,fontsize=\relsize{-1}]
+    from django.views.generic import ListView
+    from import Club
+    class ClubListView(ListView):
+        model = Club
+        context_object_name = 'clubs'
+  \end{Verbatim}
+  \vsb[0.25]
+  \begin{visibleenv}<2->
+  ||
+  \begin{Verbatim}[gobble=4,frame=single,fontsize=\relsize{-1}]
+    from django.conf.urls.defaults import *
+    from import ClubListView
+    urlpatterns = patterns('',
+      (r'^$', ClubListView.as_view()),
+      ...
+    )
+  \end{Verbatim}
+  \end{visibleenv}
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
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.