Re: how i do a update in django QuerySet like this: update table t set col_a = col_a + 2 where col_b = 1
22 views
Skip to first unread message
Tom Evans
unread,
Nov 20, 2012, 10:08:56 AM11/20/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to django...@googlegroups.com
On Tue, Nov 20, 2012 at 1:00 PM, peixinchen <shan...@gmail.com> wrote:
> how i do a update in django QuerySet like this: update table t set col_a =
> col_a + 2 where col_b = 1,
>
> i could use filter take the place of "where clause", but how "set col_a =
> col_a + 2" to being?
>
from django.db.models import F
Foo.objects.filter(col_b=1).update(col_a=F('col_a')+2)