Answer the question
In order to leave comments, you need to log in
How to infer related models in django?
Good afternoon!
Please tell me how to make a selection from related models
An example of the models.py model:
class managers(models.Model):
fio = models.CharField(max_length=100, verbose_name="ФИО")
def get_messages(self):
return self.messages.all()
class messages(models.Model):
text = models.TextField()
manager = models.ForeignKey(Managers)
def index(request):
keyWords = {
'managers': models.managers.objects.all()
}
return render_to_response('index.html', keyWords)
<table>
{% for manager in managers %}
<tr>
<td>{{ manager.fio }}</td>
<td>
{% with messages=managers.get_messages %}
<table>
{% for message in messages %}
<tr><td>{{ message.text }}</td></tr>
{% endfor %}
</table>
{% endwith %}
</td>
</tr>
{% endfor %}
</table>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question