Django search form for filtering

I am currently doing a search using forms

This is my views.py


class HomeView(generic.ListView):
    model = Consultant
    template_name = 'sogeti/home.html'

    def get_queryset(self):
        query = self.request.GET.get('q')
        if query:
            return Consultant.objects.filter(
                Q(first_name__icontains=query) |
                Q(last_name__icontains=query) |
                Q(group__***le_techGroup__contains=query) |
                Q(practices__***le_practice__contains=query)
            )
        else:
            return Consultant.objects.all()


and this is my home.html


<form action="" method="get" class="form-inline">
  <input type="text" name="q" placeholder="Enter Keyword" value="{{ request.GET.q }}" class="form-control">
  <select name="filter" class="form-control">
      <option value="all">All</option>
      <option value="people">People</option>
      <option value="certification">Certification</option>
      <option value="skillset">Skillset</option>
  </select>
  <input type="submit" value="Search" class="btn btn-default">
</form>


My first problem is that when it tries to search something (Eg: bla) that is not in my database, it returns a blank screen. Nothing at all. Tried searching but could not get any answers.

My second problem is how am I able to specify my search using HTML select and options to filter. As you can see from my home.html I have the tag with option value but no idea how to utilize it for Django.


Ifkkf



Not the answer you're looking for? Browse other questions tagged python django django-forms django-views or ask your own question.