Django three tables Association query

class School(models.Model):
    name = models.CharField(max_length=10)

class Claxx(models.Model):
    name = models.CharField(max_length=10)
    school = models.ForeignKey(School, related_name="claxxes")

class Student(models.Model):
    name = models.CharField(max_length=10)
    claxx = models.ForeignKey(Claxx, related_name="stues")

    def __str__(self):
        return self.name

School-Class-Student, three tables

Peking University

1
        ,
2
                            

how to query "all the students in Peking University"?

my simple idea is to first query all the classes below Peking University, and then traverse each class to get all the students

is there any other way, such as annotate or aggregate, can you write it out?

Please take a look at it

Jul.05,2022

Student.objects.filter(claxx__school__name='').distinct()
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ed4fb3-3514.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ed4fb3-3514.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?