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
1Order.objects.select_related('account_customer').all() \
2 .values('customer_id', 'other_field_1', ...) \
3 .annotate(total_sales=Sum('total_price')) \
4 .filter(created_at__year=today.year, created_at__month=today.month)
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