For some reason, "fio" field isn't showing up.

I am trying to derive the ‘fio’ of the lecturer and the disciplines he leads. But for some unknown reason the lecturer’s ‘fio’ is not displayed.


{% for discipline in disciplines %}
    <h3>Lecturer: {{ discipline.lector.fio }}</h3>
        <li>Discipline: {{ }}</li>
{% endfor %}

def get_lectors_disciplines(request, lector_id):
    lectors = get_object_or_404(Lector, pk=lector_id)
    disciplines = lectors.disciplines.all()
    return render(request, 'main/student_list.html',
                  {'disciplines': disciplines})

class Discipline(models.Model):
    """Discipline model"""
    slug = models.SlugField(max_length=255, unique=True, db_index=True,
    name = models.CharField(max_length=255)
    description = models.TextField(blank=True)
    lectors = models.ManyToManyField(Lector, related_name='disciplines')
    department = models.ForeignKey(Department, on_delete=models.CASCADE)

    semester = models.IntegerField(default=1)

    def __str__(self):
class Lector(models.Model):
    """Lecturer model"""
    slug = models.SlugField(max_length=255, unique=True, db_index=True)

    fio = models.CharField(max_length=255)
    photo = models.ImageField(upload_to="lector/%Y/%m/", blank=True)

    chair = models.ForeignKey(Department, on_delete=models.SET_NULL, null=True,
    salary = models.PositiveIntegerField(default=0)
    is_work = models.BooleanField(default=False)

A Discipline doesn’t have just one Lector, it has many.

So this line:

would need to be inside a loop to iterate over all the lectors:

{% for lector in discipline.lectors.all %}
    <h3>Lecturer: {{ discipline.lector.fio }}</h3>
{% endfor %}

If you want to render only the Lector that was referenced in the view, then you could add the lector from the get_object_or_404 to your context, and render it in the template.