一对多
# 基于双下划线的一对多查询 # 查询出版社为上海出版社的所有图书 # ret = Publish.objects.filter(name='上海出版社').values('book__name', 'book__price') # print(ret) # ret = Book.objects.filter(publish__name='上海出版社').values('name', 'price') # print(ret) # 查询上海出版社的价格大于40的书 # book__price__gt 书本 价格 大于 ret = Publish.objects.filter(name='上海出版社', book__price__gt=40).values('book__name', 'book__price') print(ret)
一对一
多对多
连续跨表