Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Sir, I am trying to make students and courses relationship but cannot do that

Thats the Students Model:

class Student(models.Model):
    GENDER = (
        ('F', 'Female'),
        ('M', 'Male'),
        ('O', 'Other'),
    )
    std_ID = models.CharField(max_length=12, primary_key=True, default='16201519-001')
    std_name = models.CharField(max_length=50, default='')
    std_gender = models.CharField(max_length=1, choices=GENDER, default='M')
    std_class = models.CharField(max_length=50, default='')


Thats the Courses Model:

class Courses(models.Model):
    Credits = (
        ('1', 'One'),
        ('2', 'Two'),
        ('3', 'three'),
        ('4', 'four'),
        ('6', 'Six'),
    )
    c_code = models.CharField(max_length=20, primary_key=True, default='CS-202')
    c_name = models.CharField(max_length=50)
    c_creditsHours = models.CharField(max_length=1, choices=Credits)
    courses = models.ManyToManyField(Courses)


What I have tried:

Here you can see, I am using ManyToManyField but when
First, I use the ManyToManyField, then thats show the relation ship in the side of courses but not at person side.
Second, by using the ManyToManyField, All the students already selected but i want to select some of them but cannot do that.
So please tell me how we can do that.
Posted
Updated 12-Apr-20 22:12pm
v2
Comments
[no name] 13-Apr-20 16:23pm    
You need a "Student and Course (taken)" table. That's the "relation".

i.e. a student can have many courses, and a course can have many students.
Member 14088544 14-Apr-20 11:56am    
yes thats the question how i can do that

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900