当前位置:网站首页>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
边栏推荐
- Scratch crawler mysql, Django, etc
- Bean operation domain and life cycle
- C# Socke 服务器,客户端,UDP
- Garbage disposal method based on the separation of smart city and storage and living digital home mode
- Delete a record in the table in pl/sql by mistake, and the recovery method
- 【ORM框架】
- 2020浙江省赛
- web3.0系列之分布式存储IPFS
- [untitled]
- 小程序实现页面多级来回切换支持滑动和点击操作
猜你喜欢
一大波开源小抄来袭
虚数j的物理意义
Wallys/IPQ6010 (IPQ6018 FAMILY) EMBEDDED BOARD WITH ON-BOARD WIFI DUAL BAND DUAL CONCURRENT
Google Colab装载Google Drive(Google Colab中使用Google Drive)
Garbage disposal method based on the separation of smart city and storage and living digital home mode
官媒关注!国内数字藏品平台百强榜发布,行业加速合规健康发展
Internship log - day07
ORM模型--关联字段,抽象模型类
Bean operation domain and life cycle
ORM -- logical relation and & or; Sort operation, update record operation, delete record operation
随机推荐
Es classes and objects, prototypes
高数_第1章空间解析几何与向量代数_向量的数量积
2020ccpc Weihai J - Steins; Game (SG function, linear basis)
Garbage disposal method based on the separation of smart city and storage and living digital home mode
2016 CCPC Hangzhou Onsite
Interface test
Pytest learning - dayone
ES6中的原型对象
EXT2 file system
Deep understanding of UDP, TCP
Applet popup half angle mask layer
ORM--查询类型,关联查询
Please ask me a question. I started a synchronization task with SQL client. From Mysql to ADB, the historical data has been synchronized normally
request对象对请求体,请求头参数的解析
小程序实现页面多级来回切换支持滑动和点击操作
内存==c语言1
Arcgis操作: 批量修改属性表
ORM model -- associated fields, abstract model classes
Pit using BigDecimal
Apprentissage avancé des fonctions en es6