annotated annotate

annotation是什么意思annotation 是动词 annotate 加后缀 -ion 派生出来的名词,意思是 “注解、注解、注释”,如:
He supplied annotations to nearly 15,000 musical works. 他给近1.5万部音乐作品作过注解 。
She retained a number ofcopies for further annotation. 她保留了许多副本以便作进一步的注解 。
另如动词:
Likewise directories themselves you should be able to annotate.同样地目录他们自己你应该可以注解.
However, I knew I needed my own book to annotate. 可是我知道我需要自己拥有来做笔记.
使用annotate遇到的问题 Django中QuerySet的annotate方法 可以实现分组(group by)后再聚合,返回一个queryset 。
但是在使用时得到的结果总是不对,看了对应的sql语句也不正确 。后来终于在一篇博客上找到了答案,现在将使用annotate遇到问题的过程记录下 。
使用annotate实现对 suspects 字段分组统计
先看下表中的数据
第一次尝试
可以看到默认按照 id 进行分组,并且按照默认的 creaed 排序,得到的k值都是1,和我希望的 group by suspects 不符 。
第二次尝试
发现在 group by 里还是多了个 created,在一篇博客下看到是因为模型 META 类中的默认排序被添加到被添加到查询中,然后将其添加到group by子句中,因为SQL需要这样 。查看了自己的modle,确实是这样 。
解决方法是删除默认排序或者添加空 order_by 重置顺序,我选择第二种 。
第三次尝试
终于实现了预期的效果 。
并且如果用 order_by("created") 而不是 order_by(),created 又会被添加到group_by中,这里不限于 created 这个在 META 中默认排序的字段,只要在 order_by 中添加,就会在 group_by 中
比如下面用不在 META 类中的 location 字段
group_by 依然多出了一个字段 location。
从几次结果看 order_by 最好要么为空,要么是values中的字段 。
参考博客: Django annotate 时 group by 有额外的字段
注的英文是什么注
zhù

(灌入) pour; irrigate:
【annotated annotate】浇注 pour
大雨如注 。The rain poured down.; It's a downpour.
(集中) concentrate on; fix on; focus on:
专注 concentrate one's attention on
全神贯注 concentrate on; be engrossed in, be preoccupied with
(用文字来解释字句) annotate; explain with notes; give exegesis or explanation:
评注 make commentary and annotation; give exegesis
批注 provide critical and explanatory notes for; annotate
(记载; 登记) record; register:
给学生注册 register the students
注入史册 record in historical records

(赌注) stakes:
下注 put up stakes
孤注一掷 stake everything on a single throw
(解释字句的文字) notes:
附注 annotations
脚注 footnote
annotate和comment的区别annotate
英 ['?n?te?t]美 ['?n?'tet]
vi. 注释;给…作注释或评注
vt. 注释;作注解
comment
英 ['k?ment]美 ['kɑm?nt]
n. 评论;意见;批评
vi. 发表评论;发表意见
vt. 为…作评语

annotated annotate

文章插图
请教annotate和filter顺序问题annotate和filter有区别:
第一个num_books计算了所有的书, 。
第二个num_books只计算rating3的书 。
按原文的意思就是, filter同样也限制了annotate的计算范围, 所以只有在annotate之前使用fitler, 这个filter才会对annotate有效果 。

    秒懂生活扩展阅读