O'Reilly logo

Django Unleashed by Andrew Pinkham

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

14.3 Discovering Django Pagination in the Shell

As with all Django tools, the quickest way to discover how to use the tool is to pop open the shell and start fooling around. Use the command in Example 14.1.

Example 14.1: Shell Code

$ ./manage.py

Let’s start by splitting up our tag list webpage. At the moment, we have 16 Tag objects in our database, as shown in Example 14.2.

Example 14.2: Python Interpreter Code

>>> from organizer.models import Tag >>> Tag.objects.count() 16

If we did not know about the Pagination class, we could start by slicing our queryset ourselves. In Example 14.3, we ask for all 16 Tag objects, and then use a slice to take the first five.

Example 14.3: Python Interpreter Code

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required