Reputation: 2525
In my django project I'm using Django Endless Pagination for pagination and haystack + elasticsearch for searching. When I search a specific content the request method is POST and the result is correct, but when I try to paginate through the search result, next request is received as GET and the search result is lost and the whole content is iterated.
Here is my code:
views.py
@login_required(login_url="/")
@page_template('students/students_listing_block.html')
def students(request, template='students/students_listing.html', extra_context=None, *args, **kwargs):
sqs = SearchQuerySet().models(Student)
if request.POST:
searchcontent = request.POST.get('content', None)
if searchcontent:
sqs = sqs.filter(content=searchcontent)
students = sqs.order_by('-created_at')
context = {
'students': students,
}
if extra_context is not None:
context.update(extra_context)
return render_to_response(template, context,
context_instance=RequestContext(request))
and my template
{% load endless %}
{% lazy_paginate students %}
{% for student in students %}
// Do the displaying here
{% endfor %}
{% show_more %}
Upvotes: 1
Views: 409
Reputation: 2816
It is get request because the standard request method for search is GET. My recommendation is to change the request method for search into GET.
Or, if you want to keep using POST, you need to change the request method for every page link. This is a good library to change the hyperlink request method. https://github.com/rails/jquery-ujs
<a href="/asd" data-method="post">TEST</a>
Upvotes: 0