[Django]-Django templates how loop through rows of a model

5๐Ÿ‘

โœ…

I think you may searching for something like this.

 <table>
   <tr>
     <th>Question</th>
     <th>Answers</th> 
   </tr>
   {% for q in Questions %}
   <tr>
   {% for a in q.question.all %}
       <td>{{q}}</td>
       <td>{{a.answer}}</td>
   {% endfor %}
   </tr>
   {% endfor %}
</table>
๐Ÿ‘คGeo Jacob

0๐Ÿ‘

Try to use django-tables2

It is pretty flexible and can be modified easily

๐Ÿ‘คNikolai Golub

Leave a comment