Last active
December 22, 2016 02:54
-
-
Save zhu327/c512bf581873cb709b80674bf9d6b79c to your computer and use it in GitHub Desktop.
snippet of django orm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 关联字段用select_related不能用正常使用only选取关联对象的某些字段,可以变通一下 | |
a = Articles.objects.only('title').annotate(blog_name=F('blog__name')).first() | |
a.title | |
a.blog_name | |
# Django group by | |
from django.db.models import Count | |
Members.objects.values('designation').annotate(dcount=Count('designation')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment