标签:style blog color 使用 strong io for re
# Tintin filed a news story! reporter = Reporters.objects.get(name=‘Tintin‘) reporter.stories_filed += 1 reporter.save() # 等于 from django.db.models import F reporter = Reporters.objects.get(name=‘Tintin‘) reporter.stories_filed = F(‘stories_filed‘) + 1 reporter.save()
Reporter.objects.all().update(stories_filed=F(‘stories_filed‘) + 1)
这就是F()的使用了。
使用F()的原因就是:
F() therefore can offer performance advantages by: getting the database, rather than Python, to do work reducing the number of queries some operations require 提供了性能优势: getting方法,也就是查询操作,更快 减少了某些操作的大量查询
你看这事情弄得多蛋疼?
原本SQL直接执行就爽得不行,偏要搞一层又一层,还不如直接上!
django - from django.db.models import F - class F,布布扣,bubuko.com
django - from django.db.models import F - class F
标签:style blog color 使用 strong io for re
原文地址:http://www.cnblogs.com/kevin922/p/3867924.html