Answers for "fetching data from multiple tables using related name in django"

0

fetching data from multiple tables using related name 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

fetching data from multiple tables using related name in django

Order.objects.select_related('account_customer').all() \
    .values('customer_id', 'other_field_1', ...) \
    .annotate(total_sales=Sum('total_price')) \
    .filter(created_at__year=today.year, created_at__month=today.month)
Posted by: Guest on September-13-2021
0

fetching data from multiple tables using related name 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 "fetching data from multiple tables using related name in django"

Python Answers by Framework

Browse Popular Code Answers by Language