From 924d9e2f6ac8d195160633f7413f9bd1e24836d3 Mon Sep 17 00:00:00 2001 From: Jacob Kaplan-Moss Date: Wed, 5 Apr 2006 17:26:08 +0000 Subject: magic-removal: updated tutorials 2 and 4 to be magic-removal-complient (refs #1464). Thanks to ChaosKCW and jbowtie. git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2616 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- docs/tutorial04.txt | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'docs/tutorial04.txt') diff --git a/docs/tutorial04.txt b/docs/tutorial04.txt index eccf13d647..90e3c5d4d9 100644 --- a/docs/tutorial04.txt +++ b/docs/tutorial04.txt @@ -49,13 +49,13 @@ included this line:: So let's create a ``vote()`` function in ``myproject/polls/views.py``:: from django.shortcuts import get_object_or_404, render_to_response - from django.models.polls import choices, polls from django.http import HttpResponseRedirect + from myproject.polls.models import Choice, Poll def vote(request, poll_id): - p = get_object_or_404(polls, pk=poll_id) + p = get_object_or_404(Poll, pk=poll_id) try: - selected_choice = p.get_choice(pk=request.POST['choice']) + selected_choice = p.choice_set.filter(pk=request.POST['choice']) except (KeyError, choices.ChoiceDoesNotExist): # Redisplay the poll voting form. return render_to_response('polls/detail', { @@ -102,7 +102,7 @@ After somebody votes in a poll, the ``vote()`` view redirects to the results page for the poll. Let's write that view:: def results(request, poll_id): - p = get_object_or_404(polls, pk=poll_id) + p = get_object_or_404(Poll, pk=poll_id) return render_to_response('polls/results', {'poll': p}) This is almost exactly the same as the ``detail()`` view from `Tutorial 3`_. @@ -168,10 +168,10 @@ so far:: Change it like so:: from django.conf.urls.defaults import * - + from myproject.polls.models import Poll + info_dict = { - 'app_label': 'polls', - 'module_name': 'polls', + 'queryset': Poll.objects.all(), } urlpatterns = patterns('', @@ -185,10 +185,8 @@ We're using two generic views here: ``object_list`` and ``object_detail``. Respectively, those two views abstract the concepts of "display a list of objects" and "display a detail page for a particular type of object." - * Each generic view needs to know which ``app_label`` and ``module_name`` - it's acting on. Thus, we've defined ``info_dict``, a dictionary that's - passed to each of the generic views via the third parameter to the URL - tuples. + * Each generic view needs to know which model its acting on. This + is done using a QuerySet. * The ``object_detail`` generic view expects that the ID value captured from the URL is called ``"object_id"``, so we've changed ``poll_id`` to -- cgit v1.3