当前位置:网站首页>ORM -- query type, association query
ORM -- query type, association query
2022-07-07 10:07:00 【chuntian_ tester】
ORM In the frame , An alias will be set for the primary key in each model class :pk
models.Projects.objects.filter(id=2) Equivalent to models.Projects.objects.filter(pk=2)
1.filter() and exclude() Query type
exclude() Namely filter() Reverse query of
1.1 filter() Supported query types :
models. Model class name .objects.filter( Field name __ Query type =xxxx)
Add :
filter(id__gt=2)
filter(id__gte=2)
filter(id__lt=2)
filter(id__lte=2)
1.2 exclude() Reverse query
filter() Methods support all query types
2. Relational query
When a foreign key is defined in a model class , When adding data to the table corresponding to this model class , You must also specify which data of the parent table to associate the new data from the table
2.1 stay Interfaces Define foreign keys in the model class , relation Projects Model class
2.2 transfer
After the move ,Interfaces The table generated by the model class will automatically Generate foreign keys : Foreign key name _id
2.3 Foreign key Association creation
The way 1:
2.3.1 First get the parent table model object , Only... Can be used here get(), Out-of-service filter(), why ?
2.3.2 Pass the obtained key field name other than the parent table model object as a parameter
use postman View after request interfaces surface
The way 2:
2.3.1 First get the parent table model object , Then get the parent table id value
2.3.2 Add parent table Primary key value With Foreign key name _id Pass... As a parameter
2.4 Foreign key Association query
2.4.1 Use to get parent table data from table data
utilize . The parent table model class name is lowercase obtain
Get all the project information including the registered interface
Interfaces.objects.filter(name__contains=' Registered interface ').first().projects
2.4.2 Use the parent table data to obtain the data from the table
utilize From the table model, the class name is lowercase _set obtain ;
Or in the foreign key field of the slave table model , Appoint related_name='xxxx':
models.Projects.objects.filter(leader__contains='jeanet')[0].xxxx.all()
Get the project leader=jeanet All interface information :
models.Projects.objects.filter(leader__contains='jeanet')[0].interfaces_set.all()
2.4.3 Relational query
2.4.3.1 Get the data from the parent table through the parent table parameters
From the table model class QuerySet object ( Associated attribute fields __ Field name in the parent table model class __ Query type = value )
2.4.3.2 Get the parent table data from the table parameters
Of the parent table model class QuerySet object ( From table related_name Field name __ From the field name in the table model class __ Query type = value )
边栏推荐
- Before joining the chain home, I made a competitive product analysis for myself
- 农牧业未来发展蓝图--垂直农业+人造肉
- Detailed explanation of diffusion model
- Postman interface test I
- 小程序实现页面多级来回切换支持滑动和点击操作
- C socke server, client, UDP
- Three years after graduation
- 企业实战|复杂业务关系下的银行业运维指标体系建设
- Natapp intranet penetration
- 喜马拉雅网页版每次暂停后弹窗推荐下载客户端解决办法
猜你喜欢
request对象对请求体,请求头参数的解析
中国首款电音音频类“山野电音”数藏发售来了!
Some thoughts on the testing work in the process of R & D
“十二星座女神降临”全新活动推出
基于智慧城市与储住分离数字家居模式垃圾处理方法
Wallys/IPQ6010 (IPQ6018 FAMILY) EMBEDDED BOARD WITH ON-BOARD WIFI DUAL BAND DUAL CONCURRENT
官媒关注!国内数字藏品平台百强榜发布,行业加速合规健康发展
一大波开源小抄来袭
ORM--分组查询,聚合查询,查询集QuerySet对象特性
Software modeling and analysis
随机推荐
为什么安装mysql时starting service报错?(操作系统-windows)
2020浙江省赛
Finally, there is no need to change a line of code! Shardingsphere native driver comes out
能源路由器入门必读:面向能源互联网的架构和功能
小程序弹出半角遮罩层
Pit encountered by vs2015 under win7 (successful)
字节跳动 Kitex 在森马电商场景的落地实践
HCIP 第一天 笔记整理
Why does the starting service report an error when installing MySQL? (operating system Windows)
Selenium+bs4 parsing +mysql capturing BiliBili Tarot data
Postman tutorial - scripting
基础篇:带你从头到尾玩转注解
网上可以开炒股账户吗安全吗
请教个问题,我用sql-client起了个同步任务,从MySQL同步到ADB,历史数据有正常同步过去
虚数j的物理意义
ES6中的原型对象
Deadlock caused by non clustered index in SQL Server
运用tensorflow中的keras搭建卷积神经网络
China's first electronic audio category "Yamano electronic audio" digital collection is on sale!
Scratch crawler mysql, Django, etc