Python Django和老式SQL查询
我有一个模型如下:Python Django和老式SQL查询,python,sql,django,django-models,python-2.7,Python,Sql,Django,Django Models,Python 2.7,我有一个模型如下: class call_log(models.Model): call_from = models.CharField(max_length=200) call_to = models.CharField(max_length=200) direction = models.CharField(max_length=200) end_time = models.CharField(max_length=200) duration = mo
class call_log(models.Model):
call_from = models.CharField(max_length=200)
call_to = models.CharField(max_length=200)
direction = models.CharField(max_length=200)
end_time = models.CharField(max_length=200)
duration = models.CharField(max_length=200)
total = models.DecimalField(max_digits=8, decimal_places=5, blank=True, default=0)
rate = models.DecimalField(max_digits=8, decimal_places=5, blank=True, default=0)
它有(不同)号码和sip端点发出的每个单独呼叫的记录
我要运行的SQL查询是:
SELECT DISTINCT(call_from) AS start, sum(total) AS total
FROM polls_call_log GROUP BY start;
我该如何用django写这封信
from django.db.models import Count
call_log.objects.values('call_from').annotate(Count('total'))