标签:数据库 root object 关联表 主表 ted sse tom student
示例:
- 所有学生的姓名以及其所在班级名称,QuerySet
stu_list = Student.objects.all()
select * from tb;
[obj,obj,obj,obj]
stu_list = Student.objects.all().values("id",‘username‘)
select id,username from tb;
[{"id":1,‘username‘:‘xx‘},{id:‘‘,username:‘‘}]
stu_list = Student.objects.all().values_list("id",‘username‘)
[(1,‘root‘), (2,‘alex‘)]
stu_list = Student.objects.all().values(‘username‘,"cs__name")
for row in stu_list:
print(row[‘username‘],row[‘cs__name‘])
stu_list = Student.objects.all().values(‘username‘,"cs__titile",“cs__fk__name”)
标签:数据库 root object 关联表 主表 ted sse tom student
原文地址:https://www.cnblogs.com/benchdog/p/9256609.html