django - from django.db.models import F - class F
2014-07-25 14:15
351 查看
F() 的执行不经过 python解释器,不经过本机内存,是生成 SQL语句的执行。
简写了代码:
这就是F()的使用了。
使用F()的原因就是:
# 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 Creating forms from models(用models来创建forms)
- Import Data from Excel sheet to DB Table through OAF page
- pydev 下Django 1.7 undefined variables from import问题的解决
- from django.http import HttpResponseRedirect
- (Django) How do I set limit_choices_to another class from where the ManyToManyField points to? - django, django-models - TechQues.com
- To import data from excel to DB
- Django安装失败:from setuptools import setup, find_packages ImportError: No module named setuptools
- django.db.models 的 signals 通知
- Django from setuptools import setup, find_packages 的问题
- pydev 下Django 1.7 undefined variables from import问题的解决
- django models field.db_index的使用
- 基于 Django1.10 文档的深入学习(26)—— Creating forms from models 之 基础
- Import Data from *.xlsx file to DB Table through OAF page(转)
- Import error on django models.py
- All of Django'Models
- Django Models
- Django的搜索路径与Import机制
- django.db.utils.IntegrityError:(1215, canot add foreign key constraint)
- MySQLdb DeprecationWarning: the sets module is deprecated from sets import ImmutableSet
- python 的import m.a.b 和 from m.a import b的区别