根据Django中另一列的条件,从所有行转换ListField值的总长度的总计

时间:2019-07-10 10:12:22

标签: python django mongodb django-queryset

我正在使用此代码通过遍历for循环基于其他列message_from的条件在列表字段imported_leads中查找值的数量。

    om_leads = OttMessage.objects.filter(message_from=message_from, imported_leads__0__exists=True)

    total_leads_count = 0

    for ol in om_leads:
        total_leads_count+=len(ol.imported_leads)

    print total_leads_count

有什么方法可以有效地找到total_leads_count变量值吗?我试图使用聚合来查找total_leads_count,但不知道如何在Django的ListField中使用它。任何人都可以帮助我或提供指导。  谢谢

0 个答案:

没有答案