【发布时间】:2020-10-01 08:01:01
【问题描述】:
我有一个 Student 模型,它有一个 School 模型(相关名称是 school)的外键,它本身有一个 Country 的 FK 模型(相关名称为country)。
我想选择学生及其学校和国家。 我需要这样写吗:
student = Student.objects.filter(pk=123).select_related("school", "school__country").first()
student.school # use object cache
student.school.country # use object cache
或者这样就够了:
student = Student.objects.filter(pk=123).select_related("school__country").first()
【问题讨论】:
标签: django django-orm