当前位置:网站首页>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
边栏推荐
- Introduction to energy Router: Architecture and functions for energy Internet
- Some test points about coupon test
- Gym - 102219J Kitchen Plates(暴力或拓扑序列)
- 中国首款电音音频类“山野电音”数藏发售来了!
- [untitled]
- Basic use of JMeter to proficiency (I) creation and testing of the first task thread from installation
- Natapp intranet penetration
- 企业实战|复杂业务关系下的银行业运维指标体系建设
- Please ask me a question. I started a synchronization task with SQL client. From Mysql to ADB, the historical data has been synchronized normally
- Postman tutorial - scripting
猜你喜欢
小程序弹出半角遮罩层
【学习笔记-李宏毅】GAN(生成对抗网络)全系列(一)
A wave of open source notebooks is coming
“十二星座女神降临”全新活动推出
Google Colab装载Google Drive(Google Colab中使用Google Drive)
Enterprise practice | construction of banking operation and maintenance index system under complex business relations
Use 3 in data modeling σ Eliminate outliers for data cleaning
高数_第1章空间解析几何与向量代数_向量的数量积
Performance optimization record of the company's product "yunzhujia"
Switching value signal anti shake FB of PLC signal processing series
随机推荐
14th test
Introduction to automated testing framework
企业实战|复杂业务关系下的银行业运维指标体系建设
[untitled]
Sqlplus garbled code problem, find the solution
Applet sliding, clicking and switching simple UI
Gym - 102219J Kitchen Plates(暴力或拓扑序列)
Can't connect to MySQL server on '(10060) solution summary
Bean 作⽤域和⽣命周期
Pit using BigDecimal
The physical meaning of imaginary number J
Google Colab装载Google Drive(Google Colab中使用Google Drive)
ES6中的原型对象
CDZSC_ 2022 winter vacation personal training match level 21 (2)
China's first electronic audio category "Yamano electronic audio" digital collection is on sale!
Some test points about coupon test
高数_第1章空间解析几何与向量代数_向量的数量积
大佬们,有没有遇到过flink cdc读MySQLbinlog丢数据的情况,每次任务重启就有概率丢数
网上可以开炒股账户吗安全吗
Please ask me a question. I started a synchronization task with SQL client. From Mysql to ADB, the historical data has been synchronized normally