当前位置:网站首页>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
边栏推荐
- Gauss elimination
- Before joining the chain home, I made a competitive product analysis for myself
- EXT2 file system
- C# Socke 服务器,客户端,UDP
- [learning notes - Li Hongyi] Gan (generation of confrontation network) full series (I)
- 剑指 Offer II 107. 矩阵中的距离
- C# 初始化程序时查看初始化到哪里了示例
- Apprentissage avancé des fonctions en es6
- Phpcms realizes PC website access to wechat native payment
- 2016 CCPC Hangzhou Onsite
猜你喜欢
能源路由器入门必读:面向能源互联网的架构和功能
Internship log - day07
Google colab loads Google drive (Google drive is used in Google colab)
Natapp intranet penetration
Basic use of JMeter to proficiency (I) creation and testing of the first task thread from installation
arcgis操作:dwg数据转为shp数据
Bean operation domain and life cycle
小程序滑动、点击切换简洁UI
ORM模型--关联字段,抽象模型类
web3.0系列之分布式存储IPFS
随机推荐
Win10安装VS2015
Official media attention! The list of top 100 domestic digital collection platforms was released, and the industry accelerated the healthy development of compliance
[learning notes - Li Hongyi] Gan (generation of confrontation network) full series (I)
Detailed explanation of diffusion model
喜马拉雅网页版每次暂停后弹窗推荐下载客户端解决办法
The industrial chain of consumer Internet is actually very short. It only undertakes the role of docking and matchmaking between upstream and downstream platforms
Wallys/IPQ6010 (IPQ6018 FAMILY) EMBEDDED BOARD WITH ON-BOARD WIFI DUAL BAND DUAL CONCURRENT
高斯消元
C# 初始化程序时查看初始化到哪里了示例
【原创】程序员团队管理的核心是什么?
In addition to the objective reasons for overtime, what else is worth thinking about?
Application of C # XML
Parameter sniffing (2/2)
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
Flex flexible layout
CDZSC_ 2022 winter vacation personal training match level 21 (2)
Deconvolution popular detailed analysis and nn Convtranspose2d important parameter interpretation
Guys, have you ever encountered the case of losing data when Flink CDC reads mysqlbinlog? Every time the task restarts, there is a probability of losing data
ORM -- logical relation and & or; Sort operation, update record operation, delete record operation
Es classes and objects, prototypes