在djang中过滤对象值

2024-06-17 09:33:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我的电脑里有下面的代码信号.py地址:

student.detailinfo_set.all().filter(inf="204X1001")

studentdetailinfo是型号.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")


Tags: 代码pytrans信号allfilterstudentpro
1条回答
网友
1楼 · 发布于 2024-06-17 09:33:22

要过滤查询,应该使用filter方法。如果4th column命名为fourth_column,则应使用以下代码。你知道吗

student.detailinfo_set.filter(fourth_column="204X1001")

相关问题 更多 >