class Investor(Model):
name = CharField(max_length=16)
class Project(Model):
plan_finance = IntegerField()
class ProjectProcess(Model):
project = OneToOneField('Project')
investors = ManyToManyField('Investor')
class InvestShip(Model):
project = ForeignKey('Project')
investor = ForeignKey('Investor')
invest_amount = IntegerField()
如何找到已经 已完成资助的 项目 ,换句话说,从投资者那里收到的钱' > plan_finance
答案 0 :(得分:0)
您可以在相关集上使用annotation,然后对其进行过滤。
from django.db.models import Sum
Project.objects.annotate(invested_sum=Sum('investship_set__invest_amount')).filter(invested_sum__gte=plan_finance)