Skip to content
thesarfo

Note

Limiting Results

Paging through a large queryset using Python's array slicing syntax.

views 0

Assuming you have a db of 1000 products, and you dont want to return all 1000 on the same page. You can limit the results by using python’s array slicing function.

queryset = Product.objects.all()[:5] #returns only the first 5
queryset = Product.objects.all()[5:10] #returns the second 5

The equivalent sql query can be viewed in the debug toolbar.