I have a project that lists a number of items in a certain order. This order is determined by two variables that are passed through parameters:
<a class="btn btn-info" href={{ request.path }}?key={{ key }}&orientation={{ orientation }}><i class="icon-wrench icon-large"></i></a>
“key” is the item characteristic, and “orientation” is ascending or descending. The python code handles the ordering of the items that are passed back to the template.
I have another control that needs to pass a time constraint:
<a href={{ request.path }}?time={{ time }}>{{ value }}</a>
Where time is the number of minutes.
The issue here is that if the user clicks the sort link and then clicks the time link, {{ request.path }} will only include the “proper path”, not the additional parameters that had been added.
The first sort click would yield something like
/list/items/?key=importance&orientation=asc
But the second click would return
/list/items/?time=30
Where I instead wanted to return
/list/items/?key=importance&orientation=asc&time=30
Now I could use this instead
<a href={{ request.get_full_path }}?time={{ time }}>{{ value }}</a>
But if the time link is clicked multiple times, I could end up with something like this:
/list/items/?key=importance&orientation=asc&time=30&time=60&time=15
Multiple paremeters of the same type when really I would have wanted to overwrite the original parameter of this type.
How can I resolve this issue. I’d like to retain all parameters that are not of the type being passed by the click link.
You can use this snippet http://djangosnippets.org/snippets/2105/. Example: