Try
matches = [val for val in Store.attribute_answers.all() if val in WishList.attribute_answers.all()]
Notice the parenthesis at the end of WishList.attribute_answers.all()
. Adding the parenthesis invokes the all
function to return an iterable.
If you include the parenthesis you're saying "give me all the values in the stores answers so long as that value is also in the wish lists answers". Without the parenthesis you're asking for all the values from the store's answers that are also in the all
function, which is meaningless. The all function is not an iterable (it's a function that returns an iterable)
Sounds like you are looking for something like
Store.attribute_answers.all()
If you are doing this in a template:
{% for room in study.room_choice.all %}
{{ room }}
{% empty %}
empty list!
{% endfor %}
UPDATE
If you have a through table, you can access the elements in that table (as detailed here) like so (note, you use the through table name, in lowercase, suffixing _set):
{% for roominfo in participant.roomchoicethru_set.all %}
{{ roominfo.room}} {{ roominfo.telnumber}}
{% endfor %}
all()
For everyone who finds reading code in questions as TL;DR
Instead of query_set.many_to_many
you should use
query_set.many_to_many.all()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With