Sunday 15 September 2013

Can I have multiple lists in a Django generic.ListView?

Can I have multiple lists in a Django generic.ListView?

As a Django beginner I'm working on the the tutorial provided by django
docs at https://docs.djangoproject.com/en/1.5/intro/tutorial04/
In it they demonstrate a list of multiple polls that are listed using a
query by publication date. Could I add another list to be also used in the
template to be used as well. Example Displaying a list of latest polls by
date and another by alphabetical order on the same page.
class IndexView(generic.ListView):
template_name = 'polls/index.html'
context_object_name = 'latest_poll_list'
def get_queryset(self):
"""Return the last five published polls."""
return Poll.objects.order_by('-pub_date')[:5]

No comments:

Post a Comment