如何将sql编写为django model sql语言?
select id,author_id from forum_node as answer_node where node_type='answer' and
'android' in (select tagnames from forum_node as question_node where
id=answer_node.parent_id );
任何人都可以提供帮助
答案 0 :(得分:0)
很难说没有看到模型类,但是选择相关的Forum_Node
对象看起来像这样:
Forum_Node.objects.filter(
node_type="answer",
parent__tagnames__name__in=['android']
)
或者,只获取id
和author_id
:
Forum_Node.objects.filter(
node_type="answer",
parent__tagnames__name__in=['android']
).values_list('id', 'author_id')