我的电脑里有下面的代码信号.py地址:
student.detailinfo_set.all().filter(inf="204X1001")
student
和detailinfo
是型号.py它们之间有着多对多的关系。你知道吗
当我将student.detailinfo_set.all().filter(inf="204X1001")
打印到信号.py,我得到以下输出:
<DetailInfo: 700101 - Jack Marcher/2018-09-19/Trans X101 / 204X1001 / Pro/Y2>
<DetailInfo: 700101 - Jack Marcher/2018-09-21/Trans X1 / 204X22 / Pro/Y2>
<DetailInfo: 700101 - Jack Marcher/2018-09-11/Trans X102 / 204X1001 / Pro/Y2>
<DetailInfo: 700101 - Jack Marcher/2018-09-10/Trans X1 / 204X22 / Pro/Y2>
我只想过滤每一行的第四列,即“204X1001”,这样它只会打印两行到文件中。你知道吗
丹尼尔马什金的答案如下:student.detailinfo_set.all().filter(inf="204X1001")
在我的代码中用法是错误的。
正确的用法是student.detailinfo_set.filter(inf="204X1001")
要过滤查询,应该使用filter方法。如果
4th column
命名为fourth_column
,则应使用以下代码。你知道吗相关问题 更多 >
编程相关推荐