Enhancement: ability to remove specific values from a URL
With faceted search I often need to remove specific key:value pairs from a URL while leaving other values for that key intact – e.g. with ?category=1&category=5 I might want to remove category=1 to produce ?category=5.
I've been using this tag for years and was hoping that django-spurl might be a replacement:
https://github.com/acdha/django-sugar/blob/master/sugar/templatetags/querystring_tags.py
Hi,
Does remove_query_param do what you need?
https://github.com/j4mie/django-spurl#remove_query_param
Based on the documentation, no - what I need is something like:
{% spurl base="http://example.com/?foo=bar&foo=baz" remove_query_param_value="foo","bar" %}
which produces:
http://example.com/?foo=baz
Aha, yes, sorry. Misunderstood.
It doesn't look like this functionality is in urlobject. Is it worth adding, @zacharyvoase ?
Otherwise, we could do something along the lines of:
url.set_query_param(key, [val for val in u.query_multi_dict.get(key, []) if val != value_to_remove])
Would you like to have a stab at a pull request @acdha ?
I think I'd prefer to add this functionality to remove_query_param, by extending it to handle foo=bar as well as just foo as an argument, rather than adding remove_query_param_value (unless you can think of any problems with this)
Totally necroing this - was this ever implemented?
Is this still open for a PR to fix this?
UrlObject supports this: def del_query_param_value(self, name, value)