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

Get Django Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.