[Answer]-Django ManyToMany two for loops

1👍

Inside the template, the j is something like <SearchResult: myapp.post (pk='1')>, which does not have .tags attributes. Try for j in i.object.tags.all, the .object refers the actual Model instance.

Note that Django normally does not complain about trying of accessing non-existing attributes (i.tags here) during template rendering. Hence rendering nothing may also mean incorrect attributes referring.

👤okm

0👍

Solved it by adding the tag field into the haystack searchindex. Now it outputs the list of tags. Thank you all for your help!

Leave a comment