当前位置:网站首页>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(),删除单条记录
边栏推荐
- [4g/5g/6g topic foundation-146]: Interpretation of white paper on 6G overall vision and potential key technologies-1-overall vision
- uboot机构简介
- thinkphp3.2信息泄露
- Esp8266 uses TF card and reads and writes data (based on Arduino)
- Elaborate on MySQL mvcc multi version control
- Addition, deletion, modification and query of ThinkPHP database
- iNFTnews | 时尚品牌将以什么方式进入元宇宙?
- Gym - 102219j kitchen plates (violent or topological sequence)
- 【原创】程序员团队管理的核心是什么?
- How to use clipboard JS library implements copy and cut function
猜你喜欢
Impression notes finally support the default markdown preview mode
Pit using BigDecimal
Arcgis操作: 批量修改属性表
小程序滑动、点击切换简洁UI
[4g/5g/6g topic foundation-146]: Interpretation of white paper on 6G overall vision and potential key technologies-1-overall vision
Deep understanding of UDP, TCP
What development models did you know during the interview? Just read this one
Future development blueprint of agriculture and animal husbandry -- vertical agriculture + artificial meat
EXT2 file system
企业实战|复杂业务关系下的银行业运维指标体系建设
随机推荐
H5 web player easyplayer How does JS realize live video real-time recording?
Analyze Android event distribution mechanism according to popular interview questions (II) -- event conflict analysis and handling
flinkcdc采集oracle在snapshot阶段一直失败,这个得怎么调整啊?
[4g/5g/6g topic foundation-146]: Interpretation of white paper on 6G overall vision and potential key technologies-1-overall vision
Garbage disposal method based on the separation of smart city and storage and living digital home mode
喜马拉雅网页版每次暂停后弹窗推荐下载客户端解决办法
Please ask me a question. I started a synchronization task with SQL client. From Mysql to ADB, the historical data has been synchronized normally
Three years after graduation
C# XML的应用
2020 Zhejiang Provincial Games
First issue of JS reverse tutorial
C socke server, client, UDP
Applet sliding, clicking and switching simple UI
How to become a senior digital IC Design Engineer (5-2) theory: ULP low power design technology (Part 1)
flink. CDC sqlserver. 可以再次写入sqlserver中么 有连接器的 dem
Guys, how can mysql-cdc convert the upsert message to append only
内存==c语言1
flink. CDC sqlserver. You can write the DEM without connector in sqlserver again
js逆向教程第二发-猿人学第一题
位操作==c语言2