当前位置:网站首页>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(),删除单条记录

边栏推荐
- 喜马拉雅网页版每次暂停后弹窗推荐下载客户端解决办法
- Guys, how can mysql-cdc convert the upsert message to append only
- Flex flexible layout
- 运用tensorflow中的keras搭建卷积神经网络
- Check the example of where the initialization is when C initializes the program
- Use 3 in data modeling σ Eliminate outliers for data cleaning
- Strategic cooperation subquery becomes the secret weapon of Octopus web browser
- C socke server, client, UDP
- 如何成为一名高级数字 IC 设计工程师(5-3)理论篇:ULP 低功耗设计技术精讲(下)
- 中国首款电音音频类“山野电音”数藏发售来了!
猜你喜欢

csdn涨薪技术-浅学Jmeter的几个常用的逻辑控制器使用

iNFTnews | 时尚品牌将以什么方式进入元宇宙?
![[4G/5G/6G专题基础-147]: 6G总体愿景与潜在关键技术白皮书解读-2-6G发展的宏观驱动力](/img/21/6a183e4e10daed90c66235bdbdc3bf.png)
[4G/5G/6G专题基础-147]: 6G总体愿景与潜在关键技术白皮书解读-2-6G发展的宏观驱动力

CSDN salary increase technology - learn about the use of several common logic controllers of JMeter

农牧业未来发展蓝图--垂直农业+人造肉
![[original] what is the core of programmer team management?](/img/11/d4b9929e8aadcaee019f656cb3b9fb.png)
[original] what is the core of programmer team management?
![[untitled]](/img/5b/61efbaded29250bc8d921b0cf087c8.png)
[untitled]

Future development blueprint of agriculture and animal husbandry -- vertical agriculture + artificial meat

一大波开源小抄来袭

小程序滑动、点击切换简洁UI
随机推荐
Check the example of where the initialization is when C initializes the program
How to use Mongo shake to realize bidirectional synchronization of mongodb in shake database?
arcgis操作:dwg数据转为shp数据
小程序滑动、点击切换简洁UI
小程序实现页面多级来回切换支持滑动和点击操作
flink. CDC sqlserver. You can write the DEM without connector in sqlserver again
flinkcdc采集oracle在snapshot阶段一直失败,这个得怎么调整啊?
Strategic cooperation subquery becomes the secret weapon of Octopus web browser
能源路由器入门必读:面向能源互联网的架构和功能
印象笔记终于支持默认markdown预览模式
Internship log - day04
flink. CDC sqlserver. 可以再次写入sqlserver中么 有连接器的 dem
Flinkcdc failed to collect Oracle in the snapshot stage. How do you adjust this?
Pytest learning - dayone
Pit using BigDecimal
Application of C # XML
HCIP 第一天 笔记整理
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)
Diffusion模型详解