I want to enter marks of students Grade Model i want my drop down to have only subjects selected by students

class Person(models.Model):
    lastname=models.CharField(max_length=10,null=True,blank=True)
    firstname=models.CharField(max_length=10,null=True,blank=True)
    courses=models.ManyToManyField("Course",blank=True)
    class Meta:
        verbose_name_plural="People"
    def __str__(self):
        return self.firstname + " " + self.lastname


class Course(models.Model):
    name=models.TextField()
    year=models.IntegerField()
    class Meta:
        unique_together=("name","year")
    def __str__(self):
        return f"{self.name},{self.year}"
           
class Grade(models.Model):
    person=models.ForeignKey(Person,on_delete=models.CASCADE)
    grade=models.PositiveSmallIntegerField(validators=[MinValueValidator(0),MaxValueValidator(100)])
    course=models.ForeignKey(Course,on_delete=models.CASCADE,related_name='Grades')
    def __str__(self):
        return f"{self.person},{self.grade},{self.course}"

Due to many to many relationship it display all the courses data but i need only the data which students enrolled

Back to Top