0. F介绍
在 Django QuerySets中, F() 用于直接在,数据库中引用模型的值
如果你想对一个数进行相加减,那么我推荐使用F
1. 导入
from django.db.models import F
2. F使用(注意使用F的是queryset模型对象集合)
models.Release.objects.filter(userinfo=request.user).update(release_up=F('release_up') + 1)
3. 坑 不能跨表使用(下列跨表未生效)
# topic是外键
models.Release.objects.filter(topic_id=topic_id).update(topic__people_num=F('topic__people_num') + 1)