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

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -