# template - assumes an object "all_cats" containing all categories
# or site sections you want to appear in the select list.
# Probably best to put the guts of the select loop all on one line.
<form action="" method="post">
Select another category:
<select name="type">
{% for cat in all_cats %}
<option value="{{ cat.slug }}"
{% ifequal cat.slug category.slug %}
selected="selected"{% endifequal %}
>{{ cat.title }}
{% endfor %}
</select>
<input type="submit" name="submit" value="Go" />
</form>
# views.py
# Handle the redirection.
# Assumes a reversible URL in urls.py called events_cat that takes
# cat_slug as an arg. Season to taste.
from django.http import HttpResponseRedirect
if request.POST.get('type'):
return HttpResponseRedirect(reverse('events_cat',
kwargs={'cat_slug':request.POST['type'],}))
Comments