我的模型有点像
Spot
spot_1 = 1/0
spot_2 = 1/0
spot_3 = 1/0
spot_4 = 1/0
spot_5 = 1/0
spot_6 = 1/0
类似于循环数据库,假设spot_1
代表当前月,spot_2
代表上个月,依此类推。因此,如果当前月份是6月,那么
Jun = spot_1
May = spot_2
Apr = spot_3
Mar = spot_4
Feb = spot_5
Jan = spot_6
因此,在6月底和7月份开始时,这将表示为
July = spot_1
Jun = spot_2
May = spot_3
Apr = spot_4
Mar = spot_5
Feb = spot_6
因此价值观也应继续推进。目前我循环遍历完整的QuerySet并将值设置为Move Forward。
如何使用单update()
语句实现这一目标?
答案 0 :(得分:1)
使用F
表达式:
from django.db.models import F
Spot.objects.all().update(spot_2=F('spot_1'), spot_3=F('spot_2'), ...)