【发布时间】:2021-09-21 03:44:16
【问题描述】:
我有以下模型,其中包含有关客户Leads 的所有详细信息。客户想查看他的Leads 跟进状态。
class FollowUp(models.Model):
CALL_CHOICES = [("0", "Call Unanswered"),
("1", "Call Later"),
("2", "Visit Scheduled"),
("3", "Not Visited"),
("4", "Not reachable"),
("5", "Wrong Number"),
("6", "Not Interested"),
("7", "Deal Closed")]
status = models.CharField(_("Call Status"),
max_length = 20,
choices = CALL_CHOICES,
default = '1'
)
next_action_on = DateTimeField(_("Next Action"), auto_now_add=False,
null=True, blank=True)
reminder = models.BooleanField(_("reminder"), default=False)
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
class Lead(models.Model):
followups = models.ManyToManyField(FollowUp, verbose_name=_("Follow up"), blank=True)
...
如何获得每个 status 选项的 Lead 计数。比如
{
'Call Unanswered': 12 #Leads,
'Call Later': 10 # Leads
'Visit Scheduled': 20, #Leads,
...
}
【问题讨论】:
标签: django django-models count django-queryset