models.py
class Cruski(models.Model):
name = models.CharField(max_length=40)
description = models.TextField(default='Описание кружка')
price = models.IntegerField(default=0)
def __str__(self):
return self.name
class Vospitately(models.Model):
fio = models.CharField(max_length=40)
dolshnost = models.CharField(max_length=80, default='Должность..')
image = models.ImageField()
vospet_crushek = models.ForeignKey(Cruski, related_name='vospitately')
def __str__(self):
return self.fio
views.py
def kruzhki(request):
q = Cruski.objects.all()
return render(request,'krushki.html',{'kruzki':q})
template
{% block kruzhki %}
{% for krug in kruzki %}
<p><b>{{ krug.name }}</b></p>
{% for vospet in krug.vospitately.all %}
<p> {{ vospet.fio }}</p>
{% endfor %}
<p>{{ krug.description }}</p>
<p>{{ krug.price }}</p>
{% endfor %}