David Dahan
David Dahan

Reputation: 11152

How to use Django paginator in a query-performance purpose?

I just read the doc about Django pagination.

From the example, it seems to need to be used like this:

  1. Load all the objects
  2. Create Paginator object to split objects across pages.

Now, let's say I wan't to use pagination with a very long query that returns 100000 entries. I takes a very long time to load all 100000 objects at once.

What I'd like to do is to load only 10 objects per page. Is there a way to do this using Django paginator, and maybe some limit/offset queries?

Thanks.

Upvotes: 3

Views: 744

Answers (1)

catavaran
catavaran

Reputation: 45565

No, Paginator doesn't load all objects to memory. If you pass a queryset to Paginator then it uses .count() to get number of objects.

Upvotes: 4

Related Questions