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
)
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.Even if the API won't let you do what you want, you can still improve the performance a little bit (which I assume is your intention) by using the .only method when querying the date: