Answers for "how to get data from multiple tables in django"

0

how to get data from multiple tables in django

from App.models import Student, Subject
def myFunc():
    students = Student.objects.all()
    for student in students:
        subj = student.subject.sub

def myFunc2():
    subjects = Subject.objects.all()
    for subject in subjects:
        student_name = subject.student.nm
Posted by: Guest on September-13-2021
0

how to get data from multiple tables in django

class Student(models.Model):
    sid = models.BigIntegerField(primary_key=True)
    nm = models.CharField(max_length=20, blank=True, null=True)
    subject = models.ForeignKey("Subject", related_name="student", blank=True, null=True)

class Subject(models.Model):
    sub = models.CharField(max_length=30, blank=True, null=True)
Posted by: Guest on September-13-2021

Code answers related to "how to get data from multiple tables in django"

Python Answers by Framework

Browse Popular Code Answers by Language