1.用aggregate计数
1)、统计book字段个数并用num_books指定别名
>>> from django.db.models import Count
>>> pubs = Publisher.objects.aggregate(num_books=Count('book'))
>>> pubs={'num_books':27}
2)、求picce字段平均数,没有指定别名
>>> from django.db.models import Avg
>>> Book.objects.all().aggregate(Avg('price'))
>>>{'price__avg':34.35}
3)、给查询字段指定别名
1、未指定别名
>>>data=Article.objects.values('id','title','user__username','category__name')
>>>{'id':1L,'title':'biaoti','user__username':'zhangsan','category__name':'wenxue'}
2、指定别名
>>>data=Article.objects.annotate(username=F('user__username'),category_name=F('category__name')).values('id','title','username','category_name')
>>>{'id':1L,'title':'biaoti','username':'zhangsan','category_name':'wenxue'}