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)
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
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)