2014-10-20 22 views
0

基本上我不得不这样做:的Django,在查询中使用任何

WHERE NOT (`video_video`.`id` = **ANY** (SELECT `userPreferences_history`.`video_id` FROM `userPreferences_history`)) 

但使用:

.exclude(id=history_list) 

我只是得到:

WHERE NOT (`video_video`.`id` = (SELECT `userPreferences_history`.`video_id` FROM `userPreferences_history`)) 

导致“子查询返回多于1行当我有多于1的子查询结果时。

我怎样才能做到这一点?

固定这种方式如下:Django object multiple exclude()

回答

1

假设你history_list是正确的子查询,.exclude(id__in=history_list)

+0

谢谢Peter,正是我一直在寻找的! – 2014-10-20 18:31:36

+0

通常,如果您希望从子查询中获得结果,即使只有一个可能的结果,最好使用“in”而不是“=”。 – cwallenpoole 2014-10-20 20:06:05

+0

感谢您的提示,@cwallenpoole – 2014-10-21 14:38:05