当前位置:网站首页>ORM model -- creation and query of data records
ORM model -- creation and query of data records
2022-07-07 10:07:00 【chuntian_ tester】
1. Creation of database table records
1.1 By model class name ( Field 1= value 1, Field 2= value 2...).save() The new record


1.2 By model class name .objects.create( Field 1= value 1, Field 2= value 2....) The new record


2. Query of database table records
2.1 Query multiple data
2.1.1 Query all data in the database
qs = Model class .objects.all(), What you get is a query set queryet object
a). Model class .objects.all(), return QuerySet object , Query set
b). Using model classes .objects.all(), All data in the data table corresponding to the current model class will be read out
c).QuerySet Similar list , It has the characteristics of lazy query , stay “ use ” Data Sql sentence

2.2 Query single data
2.2.1 Model class .objects.get()
This method is best to use fields with unique constraints to query
a). If you use get Query the number of records according to the specified conditions in =0 or >1, Will throw an exception
b). If you use get Query the number of records according to the specified conditions in =1, The model instance object of this record will be returned ,
Can pass Instance object . Field name To get the value of the corresponding field

2.2.2 Model class .objects.fillter()
a). You can use model classes .objects.filter( Conditions 1= value 1), return QuerySet object
b). If you use the specified criteria to query the number of records =0, Return empty QuerySet object
c). If you use the specified criteria to query the number of records >1, Wrap the qualified model object instances into QuerySet
Object
d).QuerySet object , Similar list , Has the following characteristics :
Support positive integer index value
Support slicing operation
Get the first model object :QuerySet object .first()
Get the last model object :QuerySet object .last()
To obtain the length of the :len(QuerySet object ), QuerySet object .count()
Judge query set QuerySet Whether the object is empty :QuerySet object .exists()
Support list iteration ,for Cycle, etc , Each cycle returns an instance of the model object

边栏推荐
- 使用BigDecimal的坑
- Google Colab装载Google Drive(Google Colab中使用Google Drive)
- Use 3 in data modeling σ Eliminate outliers for data cleaning
- 中国首款电音音频类“山野电音”数藏发售来了!
- CDZSC_ 2022 winter vacation personal training match level 21 (2)
- flink. CDC sqlserver. 可以再次写入sqlserver中么 有连接器的 dem
- XML配置文件解析与建模
- Phpcms realizes PC website access to wechat native payment
- The industrial chain of consumer Internet is actually very short. It only undertakes the role of docking and matchmaking between upstream and downstream platforms
- ORM -- logical relation and & or; Sort operation, update record operation, delete record operation
猜你喜欢

Memory ==c language 1

使用BigDecimal的坑

Arcgis操作: 批量修改属性表

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

Flex flexible layout

Wallys/IPQ6010 (IPQ6018 FAMILY) EMBEDDED BOARD WITH ON-BOARD WIFI DUAL BAND DUAL CONCURRENT

字节跳动 Kitex 在森马电商场景的落地实践

【学习笔记-李宏毅】GAN(生成对抗网络)全系列(一)

Basic use of JMeter to proficiency (I) creation and testing of the first task thread from installation

ORM--逻辑关系与&或;排序操作,更新记录操作,删除记录操作
随机推荐
Before joining the chain home, I made a competitive product analysis for myself
AI moves from perception to intelligent cognition
Flex flexible layout
能源路由器入门必读:面向能源互联网的架构和功能
剑指 Offer II 107. 矩阵中的距离
Analyze Android event distribution mechanism according to popular interview questions (I)
Garbage disposal method based on the separation of smart city and storage and living digital home mode
uboot机构简介
Do you have a boss to help look at this error report and what troubleshooting ideas are there? Oracle CDC 2.2.1 flick 1.14.4
HCIP 第一天 笔记整理
Finally, there is no need to change a line of code! Shardingsphere native driver comes out
Internship log - day04
Performance optimization record of the company's product "yunzhujia"
ORM模型--数据记录的创建操作,查询操作
The applet realizes multi-level page switching back and forth, and supports sliding and clicking operations
【原创】程序员团队管理的核心是什么?
Luogu p2482 [sdoi2010] zhuguosha
2020ccpc Weihai J - Steins; Game (SG function, linear basis)
字节跳动 Kitex 在森马电商场景的落地实践
phpcms实现PC网站接入微信Native支付