Skip to content Skip to sidebar Skip to footer

How To Calculate Sum And Also Cumulative Sum In Django Orm

I have table project, project has sub project and subproject has developers. Another table sprint, work distribute in sprint 1 2 ..n so on, Each sprint has different developers dat

Solution 1:

The following query will return all SprintsData objects annotated with total_sum and current_sprint_amount. From this you should be able to generate your table

from django.db.models import Sum, F
SprintsData.objects.annotate(
    total_sum=Sum(F('sprint__developers__quantity') * F('sprint__developers__charge_rate'), output_field=models.FloatField())
).annotate(
    current_sprint_amount=F('total_sum') * F('percentage')
)

SprintsData.sprint is actually a foreign key to the project model which is a little confusing

The Sprint model has no relationships to any other model so I'm not sure how you would get the sprint name


Post a Comment for "How To Calculate Sum And Also Cumulative Sum In Django Orm"