简体   繁体   中英

Django 1.6 Cant display a manytomany field from models in template

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)

The field is called language , not languages :

{% for a in doctor.language.all %}
    <p>{{ a }}</p>
{% endfor %}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM