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

边栏推荐
- 为什么安装mysql时starting service报错?(操作系统-windows)
- Gauss elimination
- Web3.0 series distributed storage IPFs
- Memory ==c language 1
- Video based full link Intelligent Cloud? This article explains in detail what Alibaba cloud video cloud "intelligent media production" is
- ORM--查询类型,关联查询
- 【ORM框架】
- A wave of open source notebooks is coming
- Win10 installation vs2015
- The Himalaya web version will pop up after each pause. It is recommended to download the client solution
猜你喜欢

Bean 作⽤域和⽣命周期

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

Internship log - day07

能源路由器入门必读:面向能源互联网的架构和功能

ORM -- logical relation and & or; Sort operation, update record operation, delete record operation

Software modeling and analysis

Qualifying 3

ORM--逻辑关系与&或;排序操作,更新记录操作,删除记录操作

官媒关注!国内数字藏品平台百强榜发布,行业加速合规健康发展

Memory ==c language 1
随机推荐
ORM model -- associated fields, abstract model classes
小程序滑动、点击切换简洁UI
Finally, there is no need to change a line of code! Shardingsphere native driver comes out
20排位赛3
虚数j的物理意义
Win10安装VS2015
Please ask me a question. I started a synchronization task with SQL client. From Mysql to ADB, the historical data has been synchronized normally
Main (argc, *argv[]) details
C# Socke 服务器,客户端,UDP
Deep understanding of UDP, TCP
The landing practice of ByteDance kitex in SEMA e-commerce scene
能源路由器入门必读:面向能源互联网的架构和功能
基础篇:带你从头到尾玩转注解
大佬们,有没有遇到过flink cdc读MySQLbinlog丢数据的情况,每次任务重启就有概率丢数
Guys, how can mysql-cdc convert the upsert message to append only
MongoDB创建一个隐式数据库用作练习
How to use Mongo shake to realize bidirectional synchronization of mongodb in shake database?
“十二星座女神降临”全新活动推出
【原创】程序员团队管理的核心是什么?
Gauss elimination