generate update query using django orm

后端 未结 3 770
囚心锁ツ
囚心锁ツ 2021-02-08 18:26

I need to implement this query using django orm:

update table set field=field+1 where id=id

I don\'t whant to use this:

o = mod         


        
3条回答
  •  广开言路
    2021-02-08 19:22

    Both the previous answerers have part of the solution: you should use update in conjunction with F():

    Model.objects.filter(id=id).update(field=F('field') +1))
    

    Note this does an in-place UPDATE without any need for SELECT at all.

提交回复
热议问题