Q:

get students in a course in django

i'm pretty new to django and i'm struggling with models and database but i managed to get some stuff right but this here isnt working out for me.
so basically what i want to do is when i click on a course it shows me a table with the students who are registered to this course but i keep getting an empty table 
models.py
from django.db import models
from django.contrib.auth import get_user_model
from django.urls import reverse
from django.utils.text import slugify

User = get_user_model()
# Create your models here
class student (models.Model):
    S_id = models.IntegerField(unique=True)
    S_fname = models.CharField(max_length=255)
    S_lname = models.CharField(max_length=255)

    def __str__(self):
        return self.S_id

class classes(models.Model):
    C_id = models.CharField(max_length=255,unique=True)
    C_name = models.CharField(max_length=255)
    C_room = models.CharField(max_length=255)
    Start_time = models.CharField(max_length=255)
    Instructs = models.ManyToManyField(User, through='Teaches')
    Registered = models.ManyToManyField(student, through='Registered')
    slug = models.SlugField(allow_unicode=True, unique=True)

    def __str__(self):
        return self.C_id

    def save(self,*args,**kwargs):
        self.slug = slugify(self.C_id)
        super().save(*args,**kwargs)
    def get_absolute_url(self):
        return reverse('classes:single',kwargs={'slug':self.slug})

    class Meta:
        ordering = ['C_name']

class Teaches(models.Model):
    Instructor = models.ForeignKey(User, related_name='St_id', on_delete=models.CASCADE)
    Course = models.ForeignKey(classes, related_name='Co_id', on_delete=models.CASCADE)

class Registered(models.Model):
    Student = models.ForeignKey(student, related_name='Stu_id', on_delete=models.CASCADE)
    Course = models.ForeignKey(classes, related_name='Cou_id', on_delete=models.CASCADE)

classes_detail.html
{% extends "classes/classes_base.html" %} {% block pregroup %}
<div class="container">
    <h1>{{classes.C_name}}</h1>
        <div class="table-responsive">
            <table class="table">
                <thead>
                    <tr>
                        <th>Student ID</th>
                        <th>Student First Name</th>
                        <th>Student Last Name</th>
                        <th>attendance</th>
                    </tr>
    </thead>
    <tbody>
        {% for student in object_list %}
            {% if student in classes.Registered.all %}
      <tr class="">
        <td>{{ student.S_id }}</td>
        <td>{{ student.S_fname }}</td>
        <td>{{ student.S_lname }}</td>
        <td></td>
      </tr>

              {% endif %}

        {% endfor %}
            </tbody>
  </table>

  </div>
</div>
{% endblock pregroup %}

views.py
from django.shortcuts import render
from django.contrib.auth.mixins import LoginRequiredMixin,PermissionRequiredMixin
from django.shortcuts import get_object_or_404
from django.urls import reverse
from django.views import generic
from .models import classes,Teaches
from django.contrib import messages

# Create your views here.
    class ListClasses(generic.ListView):
        model = classes

    class SingleClass(generic.DetailView):
        model = classes

A:

This is what your classes details template should look like:
{% for student in object.Registered.all %}
  <tr class="">
    <td>{{ student.S_id }}</td>
    <td>{{ student.S_fname }}</td>
    <td>{{ student.S_lname }}</td>
    <td></td>
  </tr>
{% endfor %}

