Reputation: 1153
I'm trying to display a manytomany field from doctor models in template. Every doctor has more than one language associated to it. So I'm trying to display languages associated to each doctor. The problem I have is that it's not showing me anything
Here is my template where I'm trying to show
{% for a in doctor.languages.all %}
<p>{{a}}</p>
{% endfor %}
Here is the 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)
Upvotes: 1
Views: 187
Reputation: 473813
The field is called language
, not languages
:
{% for a in doctor.language.all %}
<p>{{ a }}</p>
{% endfor %}
Upvotes: 1