CMS Development

MitchL
Participant

Pulling all relevant results from HubDB Multi-Select

SOLVE

Hey there, I'm trying to filter and display results from a HubDB table. I've followed this tutorial with much success: https://designers.hubspot.com/docs/tutorials/how-to-build-a-real-estate-listing-with-hubdb

 

However, I ran into an issue when trying to query the table for all rows that contain and certain value in their Multi-Select. I'm using "&categories=<multi-select-option-id>" as my parameters, and it is succeessfully pulling rows that have the specific option selected. I run into the problem with rows that have more than one option selected in the multi-select though. 

 

Screen Shot 2018-11-09 at 1.51.28 PM.png

 

{# paramaters #}

{% set queryparam = queryparam ~ "&categories="~request.query_dict.categories|urlencode %} 

 

{# Query #}

{% for row in hubdb_table_rows(dynamic_page_hubdb_table_id, queryparam)|sort(False, False, 'name') %}

 

Ex: "Dropship" is the 4th option in the multiselect. So if I use "&categories=4" as my parameters, all of the rows that have only "Dropship" selected in the multi-select will be returned, excluding those that have "Dropship" and others selected.

 

Does anyone know how to expand these paramaters to check if the desired option is listed among a multi-select that has multiple options selected? 

0 Upvotes
1 Accepted solution
MitchL
Solution
Participant

Pulling all relevant results from HubDB Multi-Select

SOLVE

Nevermind! I was able to find I solution by comparing their ids using 

 

{% for category in row.categories %}
{% if category.id == request.query_dict.categories%}

...

{% endif %}

{% endfor %}

 

View solution in original post

0 Upvotes
2 Replies 2
MitchL
Solution
Participant

Pulling all relevant results from HubDB Multi-Select

SOLVE

Nevermind! I was able to find I solution by comparing their ids using 

 

{% for category in row.categories %}
{% if category.id == request.query_dict.categories%}

...

{% endif %}

{% endfor %}

 

0 Upvotes
stabuenca
Participant | Partner
Participant | Partner

Pulling all relevant results from HubDB Multi-Select

SOLVE

You have an easy solution if you add this sufix to your variable: __contains=