Skip to content

Instantly share code, notes, and snippets.

@giasuddin90
Created October 30, 2019 10:48
Show Gist options
  • Select an option

  • Save giasuddin90/05cb8294bccebb9480a2c4dd9f8789ab to your computer and use it in GitHub Desktop.

Select an option

Save giasuddin90/05cb8294bccebb9480a2c4dd9f8789ab to your computer and use it in GitHub Desktop.
python script for generating pagination by using total number of row.
__author__ = 'giasuddin'
def pager(total_row=None, item_per_page=None):
"""
We are using this function for pagination database total row.
Then using offset for query
"""
pages = {}
total_page = total_row/item_per_page
if total_row % item_per_page != 0 and total_page > 1:
total_page += 1
for page in range(1, int(total_page) + 1):
m = page - 1
pages[page] = item_per_page * m
return pages
if __name__ == '__main__':
print(pager(100, 20))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment