当前位置:网站首页>Orm-f & Q object
Orm-f & Q object
2022-07-06 04:40:00 【Legal procedures for working in banks】
1.F object
Modify the data without extracting the created object
without F object , According to the content of the previous course , We need to implement a like function :
1. Create an object , And read the base number of likes
2. On the created object +1
3. Save the object back to the database .
It seems ok , But at the same time 100 Individuals create objects and like , The base number is 10,100 The individual saves the theory into the database at the same time after he likes it , that 100 The data saved by individuals are 10+1, Probably 100 After people like it , The result is 11. amount to 100 The data submitted by individuals to the database is 11.
and F Object directly wraps the value of the database , Use F Object is equivalent to submitting data to this field +=1, Using the lock of the database will 100 Connect individuals . No existence 100 The situation that an individual takes out the field value and saves it . amount to 100=F Personal operation +1
from django.db.models import F
def add_like(request,topic_id):
topic = Topic.objects.get(id=topic_id)
topic.like = F(' Like ') + 1
topic.save()
In addition, you can compare database field values
from django.db.models import F
from bookstore.models import Book
books = Book.objects.filter(mark_price__gt=F('price'))
for book in books:
print(book.title,' pricing :',book.price,' Present price :',book.mark_price)
2.Q object
or | And & Not ~ Wait for the operation , quote django.db.models in
Such as
from django.db.models import Q
# Search pricing and cost are less than 20 Yuan's book
Book.objects.filter(Q(price__lt=20)|Q(mark_price__lt=20))
边栏推荐
- Yyds dry goods inventory OSI & tcp/ip
- [FreeRTOS interrupt experiment]
- Introduction of several RS485 isolated communication schemes
- Tengine kernel parameters
- Lombok principle and the pit of ⽤ @data and @builder at the same time
- VNCTF2022 WriteUp
- web工程导入了mysql驱动jar包却无法加载到驱动的问题
- Solve the compilation problem of "c2001: line breaks in constants"
- JVM garbage collector concept
- Complete list of common functions of turtle module
猜你喜欢
Vulnerability discovery - vulnerability probe type utilization and repair of web applications
How do programmers teach their bosses to do things in one sentence? "I'm off duty first. You have to work harder."
二叉树基本知识和例题
CADD课程学习(7)-- 模拟靶点和小分子相互作用 (柔性对接 AutoDock)
In depth MySQL transactions, stored procedures and triggers
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Ue5 small knowledge points to enable the setting of lumen
Deep learning framework installation (tensorflow & pytorch & paddlepaddle)
[05-1, 05-02, 05-03] network protocol
View workflow
随机推荐
Patent | subject classification method based on graph convolution neural network fusion of multiple human brain maps
How do programmers teach their bosses to do things in one sentence? "I'm off duty first. You have to work harder."
[Chongqing Guangdong education] Suzhou University English film and Television Appreciation reference materials
729. My schedule I (set or dynamic open point segment tree)
Sentinel sliding window traffic statistics
BOM - location, history, pop-up box, timing
Selection of slow motion function
The implementation of the maize negotiable digital warehouse receipt standard will speed up the asset digitization process of the industry
Easyrecovery靠谱不收费的数据恢复电脑软件
优秀PM必须经历这3层蜕变!
电脑钉钉怎么调整声音
CertBot 更新证书失败解决
A blog to achieve embedded entry
Visio draws Tai Chi
P3500 [POI2010]TES-Intelligence Test(二分&离线)
Redis —— Redis In Action —— Redis 实战—— 实战篇一 —— 基于 Redis 的短信登录功能 —— Redis + Token 的共享 session 应用— 有代码
CADD course learning (7) -- Simulation of target and small molecule interaction (flexible docking autodock)
Yyds dry goods inventory OSI & tcp/ip
The value of two date types is subtracted and converted to seconds
When debugging after pycharm remote server is connected, trying to add breakpoint to file that does not exist: /data appears_ sda/d:/segmentation