MattBroach / DjangoRestMultipleModels

View (and mixin) for serializing multiple models or querysets in Django Rest Framework
MIT License
549 stars 67 forks source link

Paginations #34

Closed dmsnet closed 6 years ago

dmsnet commented 6 years ago

Can i paginate all results queryset? without per queryset pagination .

MattBroach commented 6 years ago

Unfortunately, pagination can only be provided at the queryset level. Earlier incarnations of this library (pre-2.0) had pagination on all results, but it had to be discarded. The problem was that the primary benefit of pagination is not in limiting the number of items return via the API but in limiting the number of items fetched from the database, which is usually where the big performance cost usually is. Given that, it's impossible to truly paginatate the overall results because the querysets have to be evaluated before they can be merged.

If you'd like to re-implement a version of the all-results pagination for your own code, you can take a look at how it used to be implemented. Basically, you just need to call paginate_queryset on the results (assuming they haven't already been paginated, and that the pagination_class isn't one from DjangoRestMultipleModels). I think the use case is probably narrow enough, though, that it's not going to go back into the library as it currently exists.