Django select_related查询

时间:2016-09-22 19:47:15

标签: python mysql django

我有以下两种模式:

    prevWeekTeams = UserSelection.objects.select_related().filter(soccerseason=1025,fixturematchday=5,user=currentUserID).order_by('teamselection1or2')

我使用以下查询:

Cannot resolve keyword 'soccerseason' into field. Choices are: campaignno, fixtureid, fixtureid_id, teamselection1or2, teamselectionid, teamselectionid_id, user, user_id, userselectionid

运行时出现以下错误:

{{1}}

我知道它不起作用,但我不太清楚如何在灯具表中引用soccerseason。任何帮助,将不胜感激。非常感谢,艾伦。

PS

如果您需要其他两个链接的模型,请告诉我。

1 个答案:

答案 0 :(得分:1)

您只需要使用该格式过滤外国模型的字段

在您的案例field-that-reference-to-foreign-model__foreign-model-field

fixtureid__soccerseasonThe docs充其量描述。

你应该做的是

prevWeekTeams = UserSelection.objects.filter(fixtureid__soccerseason=1025,fixtureid__fixturematchday=5,user=currentUserID).order_by('teamselection1or2')