Skip to content

Set self.count before self.limit in LimitOffsetPagination #4437

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 2, 2017
Merged

Set self.count before self.limit in LimitOffsetPagination #4437

merged 1 commit into from
May 2, 2017

Conversation

dfavato
Copy link
Contributor

@dfavato dfavato commented Aug 23, 2016

Just a minor change.

Description

By setting self.count before self.limit in the LimitOffsetPagination it is possible, if one wants, to override get_limit in order to return all records if the request has a predefined param.

For example, if one wants that all records are retrieved if url has &limit=-1, in this case, get_limit could return self.count.

Otherwise, if self.count is set after self.limit then, to achieve the same result, one has to override get_limit and paginate_queryset, or run get_limit twice.

By doing this it is possible to override get_limit in order to return all records if the request has a predefined param.

For example, if one wants that all records are retrieved if url has &limit=-1, get_limit could return self.count in this case.

Otherwise, if self.count is set after self.limit then, to achive the same result, one has to override get_limit and paginate_queryset, or run get_limit twice.
@tomchristie
Copy link
Member

Sure thing. Thanks! 👍

@tomchristie tomchristie added this to the 3.6.3 Release milestone May 2, 2017
@tomchristie tomchristie merged commit 60dbe72 into encode:master May 2, 2017
@x-7
Copy link

x-7 commented Jan 16, 2020

Consider a situation,limit and offset not in request parms,restframework wiil return all records,
but it excute two sqls,first one is that query count,another is that query all records. the first sql just
waste time and no help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants