views:

29

answers:

2

I want to have a view in my app that allows the user to remove one of many filters from the GET list, then redirect using the remaining variables in the list. How can I achieve this? Possibly having one filter-remove view that works for all the variables the user can set in the filter.

+2  A: 

If I understand you right you're looking for something like this:

from django.http import HttpResponseRedirect

def myview(request):
    mypath = ..... #your redirect
    remove_get_variable = request.GET.pop('myvar')
    return HttpResponseRedirect(mypath)

If you need this more often you could also include this functionality in a middleware!

lazerscience
@lazerscience: Ahhhh...spent most of yesterday trying to figure this out. Thnx
Stephen
+1  A: 

I think you can achieve this using jquery's library query plugin

<script>
    function deleteFilterFromQuery(filter){
        //remove this filter from url
        var newquery = $.query.Remove(filter);
        //redirect to the new url
        window.location = newquery;
    }
</script>

<a onclick="deleteFilterFromQuery(this.rel)" id="filter1RemoveLink" rel="filter1">remove filter 1 </a>
<a onclick="deleteFilterFromQuery(this.rel)" id="filter1RemoveLink" rel="filter2">remove filter 2</a>
<a onclick="deleteFilterFromQuery(this.rel)" id="filter1RemoveLink" rel="filter3">remove filter 3</a>
Spyros
this is interesting...already used lazerscience's approach to solve the problem, but it's good to know of an alternative
Stephen