Jibin Mathew
Jibin Mathew

Reputation: 5102

Update value of a column using existing column value in Django

how to perform following SQL operation using Django object:

update table set column = column+x where column>5

Upvotes: 2

Views: 1638

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 599450

You use F() expressions for this.

Table.objects.filter(column__gt=5).update(column=F('column')+1)

Note, it will help you to learn Django if you start thinking in terms of models and fields rather than tables and columns.

Upvotes: 5

Related Questions