当前位置:网站首页>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))
边栏推荐
- How does vs change the project type?
- Visio draws Tai Chi
- Sqlserver query results are not displayed in tabular form. How to modify them
- Introduction to hashtable
- [face recognition series] | realize automatic makeup
- JVM garbage collector concept
- Yyds dry goods inventory OSI & tcp/ip
- [Chongqing Guangdong education] engineering fluid mechanics reference materials of southwestjiaotonguniversity
- Basic explanation of turtle module - draw curve
- E. Best Pair
猜你喜欢
Case of Jiecode empowerment: professional training, technical support, and multiple measures to promote graduates to build smart campus completion system
Certbot failed to update certificate solution
Ue5 small knowledge points to enable the setting of lumen
题解:《单词覆盖还原》、《最长连号》、《小玉买文具》、《小玉家的电费》
Database - MySQL storage engine (deadlock)
Dry goods collection | Vulkan game engine video tutorial
Solutions: word coverage restoration, longest serial number, Xiaoyu buys stationery, Xiaoyu's electricity bill
CADD course learning (7) -- Simulation of target and small molecule interaction (flexible docking autodock)
One question per day (Mathematics)
The most detailed and comprehensive update content and all functions of guitar pro 8.0
随机推荐
最高法院,离婚案件判决标准
Sorting out the latest Android interview points in 2022 to help you easily win the offer - attached is the summary of Android intermediate and advanced interview questions in 2022
How does computer nail adjust sound
CADD course learning (7) -- Simulation of target and small molecule interaction (flexible docking autodock)
Implementation of knowledge consolidation source code 1: epoll implementation of TCP server
2327. Number of people who know secrets (recursive)
Fedora/rehl installation semanage
Case of Jiecode empowerment: professional training, technical support, and multiple measures to promote graduates to build smart campus completion system
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
Can CDC pull the Oracle table in full
[05-1, 05-02, 05-03] network protocol
【Try to Hack】john哈希破解工具
Sentinel sliding window traffic statistics
The implementation of the maize negotiable digital warehouse receipt standard will speed up the asset digitization process of the industry
729. My schedule I (set or dynamic open point segment tree)
P2022 interesting numbers (binary & digit DP)
Dry goods collection | Vulkan game engine video tutorial
Jd.com 2: how to prevent oversold in the deduction process of commodity inventory?
Digital children < daily question> (Digital DP)
JVM garbage collector concept