Django子查询插入 [英] Django subquery in insert

查看:106
本文介绍了Django子查询插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试插入一些值时,是否可以强制django进行子查询?
这产生两个单独的查询:

Is it possible to force django to make a subquery when I try to insert some values? This produces two separate queries:

CommunicationLog.objects.create(
    device='asdfasdf', 
    date_request=CommunicationLog.objects.get(pk=343).date_request, 
    content_obj_id=338, type_request=1, type_change=2
)


推荐答案

您绝对不能使用 create 没有可用的API可以让你这样做,因为这是非常不寻常的用例。你必须回到原始的sql。

You definitely cannot do it by using create. There's no available API that will let you do it, since this is very unusual use case. You have to fall back to raw sql.

这篇关于Django子查询插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆