当前位置:网站首页>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

边栏推荐
- 高斯消元
- ES类和对象、原型
- flink. CDC sqlserver. 可以再次写入sqlserver中么 有连接器的 dem
- CDZSC_2022寒假个人训练赛21级(1)
- [untitled]
- There is a problem using Chinese characters in SQL. Who has encountered it? Such as value & lt; & gt;` None`
- MongoDB创建一个隐式数据库用作练习
- Analyze Android event distribution mechanism according to popular interview questions (I)
- Thinkphp3.2 information disclosure
- 能源路由器入门必读:面向能源互联网的架构和功能
猜你喜欢

20排位赛3

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

The landing practice of ByteDance kitex in SEMA e-commerce scene

ORM模型--数据记录的创建操作,查询操作

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

中国首款电音音频类“山野电音”数藏发售来了!

request对象对请求体,请求头参数的解析

内存==c语言1

A wave of open source notebooks is coming

Internship log - day04
随机推荐
Parameter sniffing (1/2)
Write it into the SR table in the way of flinksql. It is found that the data to be deleted has not been deleted. Refer to the document https://do
为什么安装mysql时starting service报错?(操作系统-windows)
2020ccpc Weihai J - Steins; Game (SG function, linear basis)
Writing file types generated by C language
小程序滑动、点击切换简洁UI
Applet sliding, clicking and switching simple UI
Gym - 102219J Kitchen Plates(暴力或拓扑序列)
Bean operation domain and life cycle
Guys, how can mysql-cdc convert the upsert message to append only
ORM model -- associated fields, abstract model classes
Introduction to automated testing framework
喜马拉雅网页版每次暂停后弹窗推荐下载客户端解决办法
中国首款电音音频类“山野电音”数藏发售来了!
The applet realizes multi-level page switching back and forth, and supports sliding and clicking operations
Official media attention! The list of top 100 domestic digital collection platforms was released, and the industry accelerated the healthy development of compliance
Arcgis操作: 批量修改属性表
Introduction to energy Router: Architecture and functions for energy Internet
第十四次试验
哈夫曼编码压缩文件