当前位置:网站首页>ORM -- logical relation and & or; Sort operation, update record operation, delete record operation
ORM -- logical relation and & or; Sort operation, update record operation, delete record operation
2022-07-07 10:07:00 【chuntian_ tester】
1. logical relationship
1.1 And
1.1.1 filter() Separate multiple filter conditions with commas in
qs = Projects.objects.filter(id='xx', full_name='xxx')
1.1.2 Chain multiple calls filter() Method
qs = Projects.objects.filter(full_name='xxx').filter('id'='xx')
1.2 or
Use Q Class to specify or relate , For filtering conditions | Separate
qs = Projects.objects.filter(Q(full_name__contains='2') | Q(leader='jeanet'))
2. The sorting operation
QuerySet object .order_by("-id",'full_name')
Use QuerySet object .order_by(‘ Field 1’,‘ Field 2’,‘- Field 3’), By default asc Sort , You can add ‘-’ To specify the desc Descending
3. Update record operation
3.1 adopt obj. Field name =xxxx Pass after covering obj.save() Method preservation , It is for the record to be fully updated
adopt obj. Field name =xxxx Pass after covering obj.save(update_fields=[“ Field 1“,” Field 2“]) Method preservation ,
Specify the updated fields , Is to update some fields
3.2 adopt QuerySet object .update( Field name =‘xxx‘) Update multiple data
4. Delete record
4.1 QuerySet object .delete(), Delete multiple records
4.2 obj.delete(), Delete a single record
边栏推荐
- 高数_第1章空间解析几何与向量代数_向量的数量积
- 【无标题】
- Finally, there is no need to change a line of code! Shardingsphere native driver comes out
- Win10 installation vs2015
- 20排位赛3
- 大佬们,请问 MySQL-CDC 有什么办法将 upsert 消息转换为 append only 消
- 一大波开源小抄来袭
- CodeForces - 1324D Pair of Topics(二分或双指针)
- Guys, how can mysql-cdc convert the upsert message to append only
- [original] what is the core of programmer team management?
猜你喜欢
Official media attention! The list of top 100 domestic digital collection platforms was released, and the industry accelerated the healthy development of compliance
VS Code指定扩展安装位置
能源路由器入门必读:面向能源互联网的架构和功能
Video based full link Intelligent Cloud? This article explains in detail what Alibaba cloud video cloud "intelligent media production" is
【ORM框架】
Win10 installation vs2015
ES类和对象、原型
Web3.0 series distributed storage IPFs
AI从感知走向智能认知
Some thoughts on the testing work in the process of R & D
随机推荐
Web3.0 series distributed storage IPFs
HCIP 第一天 笔记整理
ES6中的原型对象
2016 CCPC Hangzhou Onsite
Software modeling and analysis
请教个问题,我用sql-client起了个同步任务,从MySQL同步到ADB,历史数据有正常同步过去
Some test points about coupon test
2020CCPC威海 J - Steins;Game (sg函数、线性基)
用flinksql的方式 写进 sr的表,发现需要删除的数据没有删除,参照文档https://do
为什么安装mysql时starting service报错?(操作系统-windows)
Pit using BigDecimal
Analyze Android event distribution mechanism according to popular interview questions (II) -- event conflict analysis and handling
内存==c语言1
CSDN salary increase technology - learn about the use of several common logic controllers of JMeter
C socke server, client, UDP
根据热门面试题分析Android事件分发机制(一)
Win10 installation vs2015
哈夫曼编码压缩文件
Introduction to uboot
Natapp intranet penetration