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

边栏推荐
- “十二星座女神降临”全新活动推出
- 洛谷P2482 [SDOI2010]猪国杀
- 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
- Thinkphp3.2 information disclosure
- 字节跳动 Kitex 在森马电商场景的落地实践
- 喜马拉雅网页版每次暂停后弹窗推荐下载客户端解决办法
- Switching value signal anti shake FB of PLC signal processing series
- Es classes and objects, prototypes
- web3.0系列之分布式存储IPFS
- Interface test
猜你喜欢

XML配置文件解析与建模

Switching value signal anti shake FB of PLC signal processing series

arcgis操作:dwg数据转为shp数据

ORM--查询类型,关联查询

企业实战|复杂业务关系下的银行业运维指标体系建设

Deep understanding of UDP, TCP
![[ORM framework]](/img/72/13eef38fc14d85978f828584e689a0.png)
[ORM framework]

ORM -- query type, association query

CentOS installs JDK1.8 and mysql5 and 8 (the same command 58 in the second installation mode is common, opening access rights and changing passwords)

Bean operation domain and life cycle
随机推荐
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 -- query type, association query
Sqlplus garbled code problem, find the solution
Advanced function learning in ES6
conda离线创建虚拟环境
Use 3 in data modeling σ Eliminate outliers for data cleaning
虚数j的物理意义
The new activity of "the arrival of twelve constellations and goddesses" was launched
Check the example of where the initialization is when C initializes the program
反卷积通俗详细解析与nn.ConvTranspose2d重要参数解释
ORM--逻辑关系与&或;排序操作,更新记录操作,删除记录操作
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
Parameter sniffing (2/2)
企业实战|复杂业务关系下的银行业运维指标体系建设
Luogu p2482 [sdoi2010] zhuguosha
HCIP 第一天 笔记整理
The applet realizes multi-level page switching back and forth, and supports sliding and clicking operations
ES类和对象、原型
Why does the starting service report an error when installing MySQL? (operating system Windows)
小程序弹出半角遮罩层