我正试图在模板中显示医生模型中的多个字段。每位医生都有不止一种语言。所以我正在尝试显示与每位医生相关的语言。我遇到的问题是它没有向我展示任何东西
这是我的模板,我正在尝试展示
{% for a in doctor.languages.all %}
<p>{{a}}</p>
{% endfor %}
这是models.py
class Language(models.Model):
'''
a = "English"
b = "Arabic"
c = "Hindi"
d = "Urdu"
e = "Bengali"
f = "Malayalam"
g = "French"
h = "Spanish"
'''
name = models.CharField(max_length=200)
def __unicode__(self):
return self.name
class Doctor(models.Model):
name = models.CharField(max_length=30)
specialization = models.ForeignKey(Specialization)
clinic = models.ForeignKey(Clinic)
seekers = models.ManyToManyField(DoctorSeeker, through='Review')
language = models.ManyToManyField(Language)
education1 = models.CharField(max_length=100)
education2 = models.CharField(max_length=100, null = True)
gender_choices = ( ('M', 'Male'), ('F','Female'),)
gender = models.CharField(max_length=5, choices = gender_choices, null=True)
profile_pic = models.ImageField(upload_to='uploads/', null=True)
statement = models.TextField(null=True)
affiliation = models.CharField(max_length=100, null = True)
def __unicode__(self):
return u"%s %s" % (self.name, self.specialization)
答案 0 :(得分:1)
该字段名为language
,而不是languages
:
{% for a in doctor.language.all %}
<p>{{ a }}</p>
{% endfor %}