Book Image

Django 1.0 Template Development

Book Image

Django 1.0 Template Development

Overview of this book

Table of Contents (17 chapters)
Django 1.0 Template Development
Credits
About the Author
About the Reviewers
Preface
Index

Pagination with generic views


As we discussed in Chapter 2, generic views are used to cut down on the number of boilerplate views we end up writing in many web applications. The paginating results in these pages are also very common, and are built into the handling of generic views.

Setting up our generic list view

Instead of replacing our current list view, let's add another URL configuration to the mycompany/press/urls.py file. Add the highlighted lines:

from django.conf.urls.defaults import *
from mycompany.press.models import PressRelease

press_list_dict = {
    'queryset': PressRelease.objects.all(),
    'template_name': 'press/list.html',
    'allow_empty': False,
    'template_object_name': 'press',
    'paginate_by': 10,
}

urlpatterns = patterns('',
    (r'detail/(?P<pid>\d+)/$','mycompany.press.views.detail'), 
    (r'list/$','mycompany.press.views.press_list'),
    (r'list2/', 
        'django.views.generic.list_detail.object_list',
        press_list_dict),
    (r'latest...