1class Student(models.Model):
2 sid = models.BigIntegerField(primary_key=True)
3 nm = models.CharField(max_length=20, blank=True, null=True)
4 subject = models.ForeignKey("Subject", related_name="student", blank=True, null=True)
5
6class Subject(models.Model):
7 sub = models.CharField(max_length=30, blank=True, null=True)
8
1from App.models import Student, Subject
2def myFunc():
3 students = Student.objects.all()
4 for student in students:
5 subj = student.subject.sub
6
7def myFunc2():
8 subjects = Subject.objects.all()
9 for subject in subjects:
10 student_name = subject.student.nm
11