当前位置:网站首页>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 )
边栏推荐
- Can't connect to MySQL server on '(10060) solution summary
- [Frida practice] "one line" code teaches you to obtain all Lua scripts in wegame platform
- Gym - 102219J Kitchen Plates(暴力或拓扑序列)
- Bit operation ==c language 2
- Internship log - day07
- 第十四次试验
- China's first electronic audio category "Yamano electronic audio" digital collection is on sale!
- Three years after graduation
- Gym - 102219j kitchen plates (violent or topological sequence)
- 喜马拉雅网页版每次暂停后弹窗推荐下载客户端解决办法
猜你喜欢
能源路由器入门必读:面向能源互联网的架构和功能
小程序滑动、点击切换简洁UI
AI moves from perception to intelligent cognition
The landing practice of ByteDance kitex in SEMA e-commerce scene
[original] what is the core of programmer team management?
Garbage disposal method based on the separation of smart city and storage and living digital home mode
Bean 作⽤域和⽣命周期
ORM--数据库增删改查操作逻辑
Future development blueprint of agriculture and animal husbandry -- vertical agriculture + artificial meat
基础篇:带你从头到尾玩转注解
随机推荐
2016 CCPC Hangzhou Onsite
Horizontal split of database
虚数j的物理意义
Some thoughts on the testing work in the process of R & D
Switching value signal anti shake FB of PLC signal processing series
Guys, how can mysql-cdc convert the upsert message to append only
Flex flexible layout
AI从感知走向智能认知
Application of C # XML
高数_第1章空间解析几何与向量代数_向量的数量积
Write VBA in Excel, connect to Oracle and query the contents in the database
运用tensorflow中的keras搭建卷积神经网络
[original] what is the core of programmer team management?
Bean operation domain and life cycle
CodeForces - 1324D Pair of Topics(二分或双指针)
基于智慧城市与储住分离数字家居模式垃圾处理方法
Postman tutorial - scripting
企业实战|复杂业务关系下的银行业运维指标体系建设
Codeforces - 1324d pair of topics
【原创】程序员团队管理的核心是什么?