当前位置:网站首页>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
边栏推荐
- ES6中的函數進階學習
- HCIP 第一天 笔记整理
- ORM -- logical relation and & or; Sort operation, update record operation, delete record operation
- 剑指 Offer II 107. 矩阵中的距离
- Postman interface test I
- [ORM framework]
- The industrial chain of consumer Internet is actually very short. It only undertakes the role of docking and matchmaking between upstream and downstream platforms
- Finally, there is no need to change a line of code! Shardingsphere native driver comes out
- 2016 CCPC Hangzhou Onsite
- Arcgis操作: 批量修改属性表
猜你喜欢
一大波开源小抄来袭
Flex flexible layout
Win10安装VS2015
企业实战|复杂业务关系下的银行业运维指标体系建设
ORM -- logical relation and & or; Sort operation, update record operation, delete record operation
Bean operation domain and life cycle
Performance optimization record of the company's product "yunzhujia"
Win10 installation vs2015
Memory ==c language 1
基础篇:带你从头到尾玩转注解
随机推荐
【原创】程序员团队管理的核心是什么?
哈夫曼编码压缩文件
Codeforces - 1324d pair of topics
Why does the starting service report an error when installing MySQL? (operating system Windows)
Gauss elimination
Using keras in tensorflow to build convolutional neural network
Deadlock caused by non clustered index in SQL Server
使用BigDecimal的坑
[original] what is the core of programmer team management?
The combination of over clause and aggregate function in SQL Server
China's first electronic audio category "Yamano electronic audio" digital collection is on sale!
官媒关注!国内数字藏品平台百强榜发布,行业加速合规健康发展
There is a problem using Chinese characters in SQL. Who has encountered it? Such as value & lt; & gt;` None`
Horizontal split of database
2020ccpc Weihai J - Steins; Game (SG function, linear basis)
A wave of open source notebooks is coming
洛谷P2482 [SDOI2010]猪国杀
Application of C # XML
Can flycdc use SqlClient to specify mysqlbinlog ID to execute tasks
第十四次试验