当前位置:网站首页>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
边栏推荐
- How to use Mongo shake to realize bidirectional synchronization of mongodb in shake database?
- 2016 CCPC Hangzhou Onsite
- Basic chapter: take you through notes
- ORM--数据库增删改查操作逻辑
- Garbage disposal method based on the separation of smart city and storage and living digital home mode
- 小程序弹出半角遮罩层
- Postman tutorial - scripting
- 小程序滑动、点击切换简洁UI
- 企业实战|复杂业务关系下的银行业运维指标体系建设
- 中国首款电音音频类“山野电音”数藏发售来了!
猜你喜欢
反卷积通俗详细解析与nn.ConvTranspose2d重要参数解释
Arcgis操作: 批量修改属性表
China's first electronic audio category "Yamano electronic audio" digital collection is on sale!
ORM--数据库增删改查操作逻辑
Natapp intranet penetration
Enterprise practice | construction of banking operation and maintenance index system under complex business relations
AI moves from perception to intelligent cognition
Wallys/IPQ6010 (IPQ6018 FAMILY) EMBEDDED BOARD WITH ON-BOARD WIFI DUAL BAND DUAL CONCURRENT
Use 3 in data modeling σ Eliminate outliers for data cleaning
Qualifying 3
随机推荐
Gym - 102219J Kitchen Plates(暴力或拓扑序列)
Scratch crawler mysql, Django, etc
大佬们,请问 MySQL-CDC 有什么办法将 upsert 消息转换为 append only 消
ORM模型--关联字段,抽象模型类
The landing practice of ByteDance kitex in SEMA e-commerce scene
小程序弹出半角遮罩层
高数_第1章空间解析几何与向量代数_向量的数量积
ES6中的函数进阶学习
Luogu p2482 [sdoi2010] zhuguosha
能源路由器入门必读:面向能源互联网的架构和功能
Pytest learning - dayone
Pit encountered by vs2015 under win7 (successful)
Performance optimization record of the company's product "yunzhujia"
The industrial chain of consumer Internet is actually very short. It only undertakes the role of docking and matchmaking between upstream and downstream platforms
sql 里面使用中文字符判断有问题,哪位遇到过?比如value<>`无`
2020CCPC威海 J - Steins;Game (sg函数、线性基)
Enterprise practice | construction of banking operation and maintenance index system under complex business relations
Main (argc, *argv[]) details
China's first electronic audio category "Yamano electronic audio" digital collection is on sale!
Introduction to energy Router: Architecture and functions for energy Internet