Hi community! I’m creating a directory using HubDB and a custom module to display that director on a page.
I have 4 filters I’m using for my directory: Industry, Neighborhood, Language, and Content Type all of which are multi-select columns in my HubDB table. Right now, all of my filters work fine but they only work one at a time. I can filter by Industry OR language, etc. But I can’t filter by Industry AND language.
Wondering if anyone has any thoughts? Here is my code:
{% set selectedIndustry = request.query_dict.industry|int %}
{% set selectedLanguage = request.query_dict.language|int %}
{% set selectedNeighborhood = request.query_dict.neighborhood|int %}
{% set selectedContent = request.query_dict.content_rating|int %}
<div class="row-fluid resources-container">
<!-- FILTERS SIDEBAR -->
<div class="span3 widget-span resources-sidebar-container">
<div class="sidebar-filters">
<aside class="filters-content">
<h2>Filter Directory</h2>
<!--Filter by Industry. -->
<form id="form_id" method="get">
<div class="filter-group">
<h4>Industry:</h4>
<select name="industry" form="form_id" onChange="this.form.submit()">
<option value="0">Show All</option>
{% set industries = hubdb_table_column(2686809, "industry").options %}
{% for choice in industries %}
{% set industry_list = industry_list~choice.id|list%}
{% if choice.id == selectedIndustry %}
<option selected="selected" value="{{ choice.id }}">{{ choice.name }}</option>
{% else %}
<option value="{{ choice.id }}">{{ choice.name }}</option>
{% endif %}
{% endfor %}
</select>
</div>
</form>
<!--Filter by Language. -->
<form id="form_id2" method="get">
<div class="filter-group">
<h4>Language:</h4>
<select name="language" form="form_id2" onChange="this.form.submit()">
<option value="0">Show All</option>
{% set languages = hubdb_table_column(2686809, "language").options %}
{% for choice in languages %}
{% set language_list = language_list~choice.id|list%}
{% if choice.id == selectedLanguage %}
<option selected="selected" value="{{ choice.id }}">{{ choice.name }}</option>
{% else %}
<option value="{{ choice.id }}">{{ choice.name }}</option>
{% endif %}
{% endfor %}
</select>
</div>
</form>
<!--Filter by Neighborhood. -->
<form id="form_id3" method="get">
<div class="filter-group">
<h4>Neighborhood:</h4>
<select name="neighborhood" form="form_id3" onChange="this.form.submit()">
<option value="0">Show All</option>
{% set neighborhoods = hubdb_table_column(2686809, "neighborhood").options %}
{% for choice in neighborhoods %}
{% set neighborhood_list = neighborhood_list~choice.id|list%}
{% if choice.id == selectedNeighborhood %}
<option selected="selected" value="{{ choice.id }}">{{ choice.name }}</option>
{% else %}
<option value="{{ choice.id }}">{{ choice.name }}</option>
{% endif %}
{% endfor %}
</select>
</div>
</form>
<!--Filter by Content Rating. -->
<form id="form_id4" method="get">
<div class="filter-group">
<h4>Content Rating:</h4>
<select name="content_rating" form="form_id4" onChange="this.form.submit()">
<option value="0">Show All</option>
{% set content_ratings = hubdb_table_column(2686809, "content_rating").options %}
{% for choice in content_ratings %}
{% set content_rating_list = content_rating_list~choice.id|list%}
{% if choice.id == selectedContent %}
<option selected="selected" value="{{ choice.id }}">{{ choice.name }}</option>
{% else %}
<option value="{{ choice.id }}">{{ choice.name }}</option>
{% endif %}
{% endfor %}
</select>
</div>
</form>
<input name="page" type="hidden" id="page" class="autocomplete" placeholder="page">
</aside>
</div>
</div>
{% set queryparam = "" %}
{% if selectedIndustry %}
{% set queryparam = queryparam ~ "&industry__contains=" ~ selectedIndustry|urlencode %}
{% endif %}
{% if selectedLanguage %}
{% set queryparam = queryparam ~ "&language__icontains="~selectedLanguage|urlencode %}
{% endif %}
{% if selectedNeighborhood %}
{% set queryparam = queryparam ~ "&neighborhood__icontains="~selectedNeighborhood|urlencode %}
{% endif %}
{% if selectedContent %}
{% set queryparam = queryparam ~ "&content_rating__icontains="~selectedContent|urlencode %}
{% endif %}