django - how to compare related Sum with a value itself -
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()
how find project have finished being financed , in other words, the money received investors' > plan_finance.
you can use annotation on related set , filter on it.
from django.db.models import sum project.objects.annotate(invested_sum=sum('investship_set__invest_amount')).filter(invested_sum__gte=plan_finance)
Comments
Post a Comment