I have the following (simplified) database model, where I refer to users of the application as "teacher":
class Student(models.Model):
teacher = models.ForeignKey('auth.User', related_name="students")
name = models.TextField()
class Task(models.Model):
teacher = models.ForeignKey('auth.User', related_name="tasks")
description = models.TextField()
class Grade(models.Model):
student = models.ForeignKey(Student, on_delete=models.CASCADE)
task = models.ForeignKey(Task, on_delete=models.CASCADE)
grade = models.FloatField()
How do I ensure that the grade belongs only to one teacher
? Or is there another way to improve my model?
Thanks
edit: I just found another SO question that answers a similar question: In django, how to limit choices of a foreignfield based on another field in the same model?
Am I right, that I "have to ensure it at the input"?