Django

Code

Ticket #2863 (closed: fixed)

Opened 2 years ago

Last modified 2 years ago

docs/tutorial03.txt missing code ??

Reported by: bonovoxmofo@gmail.com Assigned to: somebody
Milestone: Component: Documentation
Version: 0.95 Keywords:
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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.

Attachments

Change History

10/03/06 06:14:03 changed by ramiro

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).

10/23/06 02:42:04 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

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

01/17/07 16:12:17 changed by

  • milestone deleted.

Milestone Version 1.0 deleted


Add/Change #2863 (docs/tutorial03.txt missing code ??)




Change Properties
Action