当前位置:网站首页>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

边栏推荐
- 【无标题】
- Pit using BigDecimal
- CDZSC_2022寒假个人训练赛21级(2)
- Can flycdc use SqlClient to specify mysqlbinlog ID to execute tasks
- Switching value signal anti shake FB of PLC signal processing series
- Become a "founder" and make reading a habit
- Future development blueprint of agriculture and animal husbandry -- vertical agriculture + artificial meat
- China's first electronic audio category "Yamano electronic audio" digital collection is on sale!
- XML配置文件解析与建模
- 企业实战|复杂业务关系下的银行业运维指标体系建设
猜你喜欢
随机推荐
Deep understanding of UDP, TCP
Introduction to energy Router: Architecture and functions for energy Internet
Enterprise practice | construction of banking operation and maintenance index system under complex business relations
Switching value signal anti shake FB of PLC signal processing series
Thinkphp3.2 information disclosure
Basic use of JMeter to proficiency (I) creation and testing of the first task thread from installation
China's first electronic audio category "Yamano electronic audio" digital collection is on sale!
农牧业未来发展蓝图--垂直农业+人造肉
Bean 作⽤域和⽣命周期
Become a "founder" and make reading a habit
根据热门面试题分析Android事件分发机制(二)---事件冲突分析处理
ORM模型--数据记录的创建操作,查询操作
PostgreSQL reports an error when creating a trigger,
哈夫曼编码压缩文件
字节跳动 Kitex 在森马电商场景的落地实践
Main (argc, *argv[]) details
Analyze Android event distribution mechanism according to popular interview questions (II) -- event conflict analysis and handling
AI moves from perception to intelligent cognition
C socke server, client, UDP
The landing practice of ByteDance kitex in SEMA e-commerce scene








