I have a HTML drop list with certain values that I want to pass to my generic view in order to return a filtered list.
The class:
class filteredListView(generic.ListView):
template_name = 'guestlist/guestlist.html'
def get_queryset(self, **kwargs):
relation = kwargs.get('relation', None)
if relation == 'all':
return Guest.objects.all()
if relation == 'grooms_side':
return Guest.objects.filter(grooms_side=True)
if relation == 'brides_side':
return Guest.objects.filter(brides_side=True)
if relation == 'friends':
return Guest.objects.filter(friends=True)
html block:
<th colspan="4">
<label>Filter by Relation
<select onchange="location='filtered'">
<option value="all">All</option>
<option value="grooms_side">Groom's Side</option>
<option value="brides_side">Brides's Side</option>
<option value="friends">Friends</option>
</select>
</label>
</th>
I've tried passing the value with a normal href
like a regular view but that gave me a NoReverseMatch
exception.
urls.py:
from django.conf.urls import url
from . import views
app_name = 'guestlist'
urlpatterns = [
# /guestlist/
url(r'^$', views.indexView.as_view(), name='index'),
# /guestlist/
url(r'^guestlist/$', views.guestListView.as_view(), name='guestlist'),
# /guestlist/add
url(r'^guestlist/add/$', views.guestCreate.as_view(), name='add'),
# /guestlist/filtered
url(r'^guestlist/filtered$', views.filteredListView.as_view(), {'relation': 'relation'}, name='filtered'),
]
My question is how do i pass the value from the drop list's options to the view. Thanks.
Edit: I've changed a few things according to one of the answers but the question still stands. What do I put in the dict in urls.py
in order to pass the value?