#2863 closed defect (fixed)
docs/tutorial03.txt missing code ??
Reported by: | 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 , 18 years ago
comment:2 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
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 thedjango.views.generic.date_based.archive_index
GV withnum_latest
in tutorial 4 (but I suspect this would make the tutorial more complex than it should).