django中的ANDed-ORed查询

时间:2013-08-07 14:20:32

标签: django django-models django-queryset

我想执行以下查询,该查询在Django中根据ANDed和ORed状态共同过滤掉模型。

SQL中的查询是这样的:

SELECT * FROM WebReply WHERE (conversation_id = conversation_id AND (user_id = ids OR sent_to = ids))

这是我在Django中写的,它引发了错误non-keyword arg after keyword arg django

web_reply_data = WebReply.objects.filter(conversation_id = conversation_id, 
                                                        (Q(user_id = ids) |  Q(sent_to = ids)))

我哪里错了?

1 个答案:

答案 0 :(得分:3)

试试这个:

web_reply_data = WebReply.objects.filter(conversation_id = conversation_id).filter( Q(user_id = ids) |  Q(sent_to = ids))