In a Django CBV (ListView), after submitting a form using GET method, with filter_1
and filter_2
fields, the resulting URL I get is something like:
http://example.com/order/advanced-search?filter_1=foo&filter_2=bar
Everything is ok. However, I'd like to use pagination, proving to my template a URL like:
http://example.com/order/advanced-search?page=2&filter_1=foo&filter_2=bar
Let's say I could override this method for this purpose:
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['my_form_values'] = self.request.GET
Now, how can I use my_form_values
in my pagination template to display the right URLs?
For now, here is my (simplified) pagination template code:
{% for num in page_obj.page_range %}
{% if page_obj.number == num %}
<li class="page-item active">
<span class="page-link">{{ num }}</span>
</li>
{% else %}
<li class="page-item">
<a class="page-link" href="?page={{ num }}">{{ num }}</a>
</li>
{% endif %}
{% endfor %}