当前位置:网站首页>ORM -- grouping query, aggregation query, query set queryset object properties
ORM -- grouping query, aggregation query, query set queryset object properties
2022-07-07 10:07:00 【chuntian_ tester】
1. Group query
1.1. Use QuerySet object .values(‘ Parent table primary key id’).annotate( Aggregate functions (‘ From the table model, the class name is lowercase ')
1.2. The master-slave table will be automatically connected , Take the foreign key field as the grouping condition
2. Aggregate operations
2.1. Use QuerySet object .aggregate( Aggregate functions (' Field name ')) Method , Return dictionary data
2.2. In the returned dictionary data key by Field name __ Aggregate function name A lowercase letter
2.3. Key parameter form can be used , In the returned dictionary data key Is the keyword parameter name
qs = Projects.objects.filter(full_name__contains='x').aggregate(Count("id"))
qs = Projects.objects.filter(full_name__contains='x').aggregate(count=Count("id"))
3. Query set QuerySet Properties of objects :
3.1 Support chain calls
You can call... Multiple times on a query set filter(),exclude() Method
3.2 Lazy query
Execute only when using data Sql sentence , In order to improve the read and write performance of the database
3.3 Will execute Sql Statement scenario :
len(),count(), Take value through index , section ,for loop ,print etc.
边栏推荐
- 官媒关注!国内数字藏品平台百强榜发布,行业加速合规健康发展
- Finally, there is no need to change a line of code! Shardingsphere native driver comes out
- CDZSC_2022寒假个人训练赛21级(1)
- Google colab loads Google drive (Google drive is used in Google colab)
- ISP、IAP、ICP、JTAG、SWD的编程特点
- [ORM framework]
- The landing practice of ByteDance kitex in SEMA e-commerce scene
- Main (argc, *argv[]) details
- Detailed explanation of diffusion model
- The Himalaya web version will pop up after each pause. It is recommended to download the client solution
猜你喜欢
反卷积通俗详细解析与nn.ConvTranspose2d重要参数解释
Garbage disposal method based on the separation of smart city and storage and living digital home mode
Es classes and objects, prototypes
Sqlplus garbled code problem, find the solution
Performance optimization record of the company's product "yunzhujia"
Flex flexible layout
Basic use of JMeter to proficiency (I) creation and testing of the first task thread from installation
Google Colab装载Google Drive(Google Colab中使用Google Drive)
【原创】程序员团队管理的核心是什么?
使用BigDecimal的坑
随机推荐
Wallys/IPQ6010 (IPQ6018 FAMILY) EMBEDDED BOARD WITH ON-BOARD WIFI DUAL BAND DUAL CONCURRENT
20排位赛3
ORM--数据库增删改查操作逻辑
Introduction to uboot
剑指 Offer II 107. 矩阵中的距离
Video based full link Intelligent Cloud? This article explains in detail what Alibaba cloud video cloud "intelligent media production" is
使用BigDecimal的坑
Scratch crawler mysql, Django, etc
Introduction to automated testing framework
A wave of open source notebooks is coming
Using keras in tensorflow to build convolutional neural network
Deconvolution popular detailed analysis and nn Convtranspose2d important parameter interpretation
位操作==c语言2
ISP、IAP、ICP、JTAG、SWD的编程特点
Before joining the chain home, I made a competitive product analysis for myself
Why does the starting service report an error when installing MySQL? (operating system Windows)
运用tensorflow中的keras搭建卷积神经网络
Garbage disposal method based on the separation of smart city and storage and living digital home mode
There is a problem using Chinese characters in SQL. Who has encountered it? Such as value & lt; & gt;` None`
Or in SQL, what scenarios will lead to full table scanning