Need Advice On Implementing Feature Regarding Django Models
Solution 1:
First of all, it's not difficult what you are looking for with some investigation work. There is a lot of information everywhere about the ManyToManyField, as @little_birdie said. To learn about this: https://docs.djangoproject.com/en/2.0/topics/db/examples/many_to_many/.
By the way, what you want is to relate the course with a teacher and all the students:
classTeacher(Model):
name =CharField(max_length=50)
# etcclassStudent(Model):
name =CharField(max_length=50)
age = IntegerField()
# etcclassCourse(Model):
subject = CharField(max_length=30)
teacher = ForeignKey(Teacher)
students = ManyToManyField(Student)
open = BooleanField(default=False)
That's what ManyToManyField does. It creates a intermediate table relating both a course and a student. If I were you, I would use a Model Form of Course model to work with the interface:
classCourseForm(ModelForm):
class Meta:
model = Course
fields = "__all__"
Every time a teacher needs to enroll students to a specific course, he would access to a form page. He would assign all the students he wants to the course and then would open the course so that students can see the course. After this, all you need to do is to save the form posted. And, of course, to work with proper interfaces for students and teachers.
Post a Comment for "Need Advice On Implementing Feature Regarding Django Models"