当前位置:网站首页>ORM--逻辑关系与&或;排序操作,更新记录操作,删除记录操作
ORM--逻辑关系与&或;排序操作,更新记录操作,删除记录操作
2022-07-07 07:17:00 【chuntian_tester】
1.逻辑关系
1.1 与
1.1.1 filter()中用逗号分隔多个过滤条件
qs = Projects.objects.filter(id='xx', full_name='xxx')
1.1.2 链式多次调用filter()方法
qs = Projects.objects.filter(full_name='xxx').filter('id'='xx')
1.2 或
使用Q类来指定或关系,过滤条件用 | 分隔
qs = Projects.objects.filter(Q(full_name__contains='2') | Q(leader='jeanet'))

2.排序操作
QuerySet对象.order_by("-id",'full_name')使用QuerySet对象.order_by(‘字段1’,‘字段2’,‘-字段3’),默认使用asc排序,可以通过字段前加‘-’来指定desc降序

3.更新记录操作
3.1 通过obj.字段名=xxxx覆盖后通过obj.save()方法 保存,是为记录全更新
通过obj.字段名=xxxx覆盖后通过obj.save(update_fields=[“字段1“,”字段2“])方法 保存,
指定更新的字段,是为部分字段更新

3.2 通过QuerySet对象.update(字段名=‘xxx‘)更新多条数据

4.删除记录操作
4.1 QuerySet对象.delete(),删除多条记录

4.2 obj.delete(),删除单条记录

边栏推荐
- Introduction to automated testing framework
- 内存==c语言1
- Application of C # XML
- Writing file types generated by C language
- 基础篇:带你从头到尾玩转注解
- Gym - 102219J Kitchen Plates(暴力或拓扑序列)
- CentOS installs JDK1.8 and mysql5 and 8 (the same command 58 in the second installation mode is common, opening access rights and changing passwords)
- Addition, deletion, modification and query of ThinkPHP database
- ViewPager2和VIewPager的區別以及ViewPager2實現輪播圖
- How will fashion brands enter the meta universe?
猜你喜欢

JS reverse tutorial second issue - Ape anthropology first question

Impression notes finally support the default markdown preview mode

小程序弹出半角遮罩层

小程序实现页面多级来回切换支持滑动和点击操作

Applet popup half angle mask layer

喜马拉雅网页版每次暂停后弹窗推荐下载客户端解决办法

内存==c语言1

基础篇:带你从头到尾玩转注解

一大波开源小抄来袭

Octopus future star won a reward of 250000 US dollars | Octopus accelerator 2022 summer entrepreneurship camp came to a successful conclusion
随机推荐
PostgreSQL创建触发器的时候报错,
C# 初始化程序时查看初始化到哪里了示例
印象笔记终于支持默认markdown预览模式
CDZSC_2022寒假个人训练赛21级(1)
小程序实现页面多级来回切换支持滑动和点击操作
Lesson 1: finding the minimum of a matrix
web3.0系列之分布式存储IPFS
iNFTnews | 时尚品牌将以什么方式进入元宇宙?
Difference between process and thread
Hcip first day notes sorting
How will fashion brands enter the meta universe?
洛谷P2482 [SDOI2010]猪国杀
Gym - 102219j kitchen plates (violent or topological sequence)
用flinksql的方式 写进 sr的表,发现需要删除的数据没有删除,参照文档https://do
Gauss elimination
2020 Zhejiang Provincial Games
Sqlplus garbled code problem, find the solution
【原创】程序员团队管理的核心是什么?
There is a problem using Chinese characters in SQL. Who has encountered it? Such as value & lt; & gt;` None`
Basic chapter: take you through notes