0

我有一个模型如下:

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;

我如何在 / for django 中写这个?

4

1 回答 1

0
from django.db.models import Count
call_log.objects.values('call_from').annotate(Count('total'))
于 2013-01-07T09:24:21.360 回答