注释ManyToMany字段并返回queryset- Django

时间:2018-10-15 13:29:14

标签: python django

我的代码如下:

Class A:
    amount = models.DecimalField();

Class B:
    amount = models.DecimalField();

Class C:
    amount = models.DecimalField();

Class D:
    amount = models.DecimalField();



Class Common(models.Model):
    a = models.ManyTomanyField(A)
    b = models.ManyTomanyField(B)
    c = models.ManyTomanyField(C)
    d = models.ManyTomanyField(D)

commons = Common.objects.values('id').annotate(total_spent=Sum(F('A__amount') + F('B__amount') - F('c__amount') - F('d__amount')).filter(total_spent__lte=0)

预期的通用查询集将为   queryset = a__amount + b__amount-c__amount-d__amount == 0

0 个答案:

没有答案