Skip to content

Instantly share code, notes, and snippets.

@level09
Last active February 23, 2016 20:09
Show Gist options
  • Save level09/0a1a803844a97abad918 to your computer and use it in GitHub Desktop.
Save level09/0a1a803844a97abad918 to your computer and use it in GitHub Desktop.
PER_PAGE = 30
def records_for_page(page=1):
results = Property.objects.filter.order_by('-date').skip((page-1)*PER_PAGE).limit(PER_PAGE)
count = Property.objects.filter.order_by('-date').skip((page-1)*PER_PAGE).limit(PER_PAGE).count()
return count, results
@bp_public.route('/',defaults={'page':1},methods=['GET'])
@bp_public.route('/page/<int:page>')
def index(page):
count, results = records_for_page(page)
if len(results) < 1 and page !=1:
abort(404)
pagination = Pagination(page, PER_PAGE,count)
return render_template('index.html',pagination=pagination,properties=results)
@bp_public.app_template_global('url_for_other_page')
def url_for_other_page(page):
args = request.view_args.copy()
#need to copy this shit
args['page'] = page
return url_for(request.endpoint, **args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment