python - Django templates how loop through rows of a model -
is there way loop through rows of model table. useful if exclude fields. making form user can create creating there own questions inquire in 1 model , model answers
for example:
model.py
class questions(models.model): name = models.charfield() question1 = models.charfield() question2 = models.charfield() ect class answers(models.model): question = models.foreignkey(questions, related_name='question') qustion_no = models.integerfield() reply = models.charfield()
form.html
<table> <tr> <th>question</th> <th>answers</th> </tr> {% q in questions %} <tr> <td>{{q}}</td> <td>{{q.question}}</td </tr> {% endfor %} </table>
i think may searching this.
<table> <tr> <th>question</th> <th>answers</th> </tr> {% q in questions %} <tr> {% in q.question.all %} <td>{{q}}</td> <td>{{a.answer}}</td> {% endfor %} </tr> {% endfor %} </table>
python django
No comments:
Post a Comment