当有两个表,例如一个学生表,一个班级表,是多对一的关系。
方法1:
c = models.Class.object.get(pk=1)
#查询到ID为1的班级
stus = models.Student.object.filter(cls=c)
# 查询出来所有班级为c的学生
#stus是多个对象
#可以循环出结果
for stu in stus :
print stu.id,stu.name
方法2
stus = models.St
当有两个表,例如一个学生表,一个班级表,是多对一的关系。
c = models.Class.object.get(pk=1)
#查询到ID为1的班级
stus = models.Student.object.filter(cls=c)
# 查询出来所有班级为c的学生
#stus是多个对象
#可以循环出结果
for stu in stus :
print stu.id,stu.name
stus = models.St