Note that there are some explanatory texts on larger screens.

plurals
  1. POPagination django
    primarykey
    data
    text
    <p>I have a view related to the index.html</p> <p>in the view I have a form to filter a query , and a table where i put the elements i got from the query</p> <p>Recently I added a pagination because some times the query can have thousands of results. </p> <p>I used the example shown here <a href="https://docs.djangoproject.com/en/1.5/topics/pagination/" rel="nofollow">https://docs.djangoproject.com/en/1.5/topics/pagination/</a></p> <p>If I use the form and make a query I got the data paginated, but if I click next I lost the data I had in the form, so the query change</p> <p>The problem I see is that the form respond to a POST method, but clicking "next" produce a request with GET method, so when <code>form = FilterForm(request.POST)</code> is executed, the form is valid, but empty</p> <p>Thanks</p> <p>EDIT: </p> <p>example code of the view</p> <pre><code>if request.method == 'POST': # If the form has been submitted... form = FilterForm(request.POST) # A form bound to the POST data if form.is_valid(): total_events_list = Make the Query else: form = FilterForm() # An unbound form total_events_list = Make another Query paginator = Paginator(total_events_list, PAGE_LIMIT, orphans=9) try: latest_events_list = paginator.page(page) except PageNotAnInteger: # If page is not an integer, deliver first page. latest_events_list = paginator.page(1) except EmptyPage: # If page is out of range (e.g. 9999), deliver last page of results. latest_events_list = paginator.page(paginator.num_pages) context = {'latest_events_list': latest_events_list, 'form': form} return render_to_response('db_interface/index.html', context, context_instance=RequestContext(request)) </code></pre> <p>The template , the form to filter the query</p> <pre><code>&lt;p&gt; Filter events &lt;/p&gt; &lt;form action="/db_interface/" method="POST"&gt;{% csrf_token %} FORM &lt;input type="submit" name ="filter" value="Submit" /&gt; &lt;/form&gt; {% if latest_events_list %} &lt;form action="indexzip" method="POST"&gt; {% csrf_token %} {% for event in latest_events_list %} SHOW DATA {% endfor %} &lt;div class="pagination"&gt; &lt;span class="step-links"&gt; {% if latest_events_list.has_previous %} &lt;a href="?page={{ latest_events_list.previous_page_number }}"&gt;previous&lt;/a&gt; {% endif %} &lt;span class="current"&gt; Page {{ latest_events_list.number }} of {{ latest_events_list.paginator.num_pages }}. &lt;/span&gt; {% if latest_events_list.has_next %} &lt;a href="?page={{ latest_events_list.next_page_number }}"&gt;next&lt;/a&gt; {% endif %} &lt;/span&gt; &lt;/div&gt; &lt;/form&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload