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

边栏推荐
- A wave of open source notebooks is coming
- CSDN salary increase technology - learn about the use of several common logic controllers of JMeter
- arcgis操作:dwg数据转为shp数据
- 2020CCPC威海 J - Steins;Game (sg函数、线性基)
- In addition to the objective reasons for overtime, what else is worth thinking about?
- Why are social portals rarely provided in real estate o2o applications?
- Gauss elimination
- Become a "founder" and make reading a habit
- Guys, how can mysql-cdc convert the upsert message to append only
- Arcgis操作: 批量修改属性表
猜你喜欢

Switching value signal anti shake FB of PLC signal processing series

Use 3 in data modeling σ Eliminate outliers for data cleaning

Performance optimization record of the company's product "yunzhujia"

The applet realizes multi-level page switching back and forth, and supports sliding and clicking operations

小程序实现页面多级来回切换支持滑动和点击操作

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

Introduction to energy Router: Architecture and functions for energy Internet

Internship log - day04

反卷积通俗详细解析与nn.ConvTranspose2d重要参数解释

基于智慧城市与储住分离数字家居模式垃圾处理方法
随机推荐
The Himalaya web version will pop up after each pause. It is recommended to download the client solution
Analyze Android event distribution mechanism according to popular interview questions (I)
flink. CDC sqlserver. 可以再次写入sqlserver中么 有连接器的 dem
Deadlock caused by non clustered index in SQL Server
ES6中的函数进阶学习
视频化全链路智能上云?一文详解什么是阿里云视频云「智能媒体生产」
剑指 Offer II 107. 矩阵中的距离
Phpcms realizes PC website access to wechat native payment
VS Code指定扩展安装位置
The new activity of "the arrival of twelve constellations and goddesses" was launched
Pit encountered by vs2015 under win7 (successful)
flink. CDC sqlserver. You can write the DEM without connector in sqlserver again
Postman interface test I
Horizontal split of database
Pit using BigDecimal
有没有大佬帮忙看看这个报错,有啥排查思路,oracle cdc 2.2.1 flink 1.14.4
Parameter sniffing (1/2)
Bit operation ==c language 2
【学习笔记-李宏毅】GAN(生成对抗网络)全系列(一)
2016 CCPC Hangzhou Onsite