Opened 18 years ago

Closed 18 years ago

Last modified 17 years ago

#2863 closed defect (fixed)

docs/tutorial03.txt missing code ??

Reported by: bonovoxmofo@… Owned by: somebody
Component: Documentation Version: 0.95
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

On docs/tutorial03.txt you are talking about limit the list of polls to five, but since you introduce render_to_response() you forgot to include that piece of code.

{{
from django.shortcuts import render_to_response

from mysite.polls.models import Poll

def index(request):

latest_poll_list = Poll.objects.all().order_by('-pub_date')
return render_to_response('polls/index.html', {'latest_poll_list': latest_poll_list})

}}

It should be

{{
from django.shortcuts import render_to_response

from mysite.polls.models import Poll

def index(request):

latest_poll_list = Poll.objects.all().order_by('-pub_date')[:5]
return render_to_response('polls/index.html', {'latest_poll_list': latest_poll_list})

}}

Thanks.

Change History (3)

comment:1 by Ramiro Morales, 18 years ago

Well, later in tutorial 4 when generic views (GV) are introduced, that hand made Poll list view is replaced with a generic one (django.views.generic.list_detail.object_list) that iterates thru all the Poll objects without sorting them by date nor slicing the QuerySet.

So, for consistency, perhaps the suggestion would be the opposite: change the first example of tutorial 3 so it doesn't use the .order_by('-pub_date')[:5] suffix either. Or apply what bonovoxmofo suggests above but use the django.views.generic.date_based.archive_index GV with num_latest in tutorial 4 (but I suspect this would make the tutorial more complex than it should).

comment:2 by Malcolm Tredinnick, 18 years ago

Resolution: fixed
Status: newclosed

(In [3912]) Fixed #2863 -- Fixed a small typo in one of the examples. Thanks
bonovoxmofo@….

comment:3 by (none), 17 years ago

milestone: Version 1.0

Milestone Version 1.0 deleted

Note: See TracTickets for help on using tickets.
Back to Top