当前位置:网站首页>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(),删除单条记录
边栏推荐
- PostgreSQL reports an error when creating a trigger,
- 哈夫曼编码压缩文件
- Applet popup half angle mask layer
- Garbage disposal method based on the separation of smart city and storage and living digital home mode
- Diffusion模型详解
- Strategic cooperation subquery becomes the secret weapon of Octopus web browser
- Lecture 1: stack containing min function
- Addition, deletion, modification and query of ThinkPHP database
- Detailed explanation of diffusion model
- The combination of over clause and aggregate function in SQL Server
猜你喜欢
iNFTnews | 时尚品牌将以什么方式进入元宇宙?
[untitled]
印象笔记终于支持默认markdown预览模式
How will fashion brands enter the meta universe?
中国首款电音音频类“山野电音”数藏发售来了!
PLC信号处理系列之开关量信号防抖FB
In fact, it's very simple. It teaches you to easily realize the cool data visualization big screen
Detailed explanation of diffusion model
CSDN salary increase technology - learn about the use of several common logic controllers of JMeter
基于智慧城市与储住分离数字家居模式垃圾处理方法
随机推荐
Bean 作⽤域和⽣命周期
In fact, it's very simple. It teaches you to easily realize the cool data visualization big screen
flink. CDC sqlserver. 可以再次写入sqlserver中么 有连接器的 dem
细说Mysql MVCC多版本控制
Win10安装VS2015
CodeForces - 1324D Pair of Topics(二分或双指针)
The applet realizes multi-level page switching back and forth, and supports sliding and clicking operations
Internship log - day04
js逆向教程第二发-猿人学第一题
How to become a senior digital IC Design Engineer (1-6) Verilog coding Grammar: Classic Digital IC Design
Internship log - day07
Lesson 1: finding the minimum of a matrix
Sword finger offer II 107 Distance in matrix
终于可以一行代码也不用改了!ShardingSphere 原生驱动问世
CDZSC_ 2022 winter vacation personal training match level 21 (1)
Niuke - Huawei question bank (61~70)
2020 Zhejiang Provincial Games
Deep understanding of UDP, TCP
【frida实战】“一行”代码教你获取WeGame平台中所有的lua脚本
Lesson 1: hardness of eggs