Calculate quarterly statistics django

0

I have to show different statistics in a project in django, so far it works well, when I calculate them, but I need to make quarterly cuts, how could I do it? I leave you the view.py

def inicio(request):
    plan_gral = jovenclub.objects.aggregate(sum=Sum('plan_gral'))//Calculo el plan GENERAl
    juridic_gral = ingresos.objects.aggregate(sum=Sum('juridico'))
    natural_gral = ingresos.objects.aggregate(sum=Sum('natural'))
    general = juridic_gral['sum']+natural_gral['sum'] //Calculo el ingreso juridico + el Natural
    porciento_general = general*100/plan_gral['sum']// calculo el % de Cumpliemiento
    ingreso = ingresos.objects.all()

In my model I have a date field also in the view also create filters to the database by date range to separate the trimestes, example:

 # TRIMESTRES
  inicio_primertrimestre = datetime(2017, 1, 1)
  final_primertrimestre = datetime(2017, 3, 31)
  primer_trimestre=ingresos.objects.filter(fecha__range=(inicio_primertrimestre, final_primertrimestre))

in the view I have something like that

 {% for datos in segundo_trimestre %}
<ul>
<li>{{datos.jovenclub}} {{ datos.fecha }} {{ datos.general }} </li>
</ul>
{% endfor %}

when I do the render if they are fixed if I do the query for data entered in that range of dates ... but when I try to see the TOTAL of INgresos for those months ... it does not show anything

How could you calculate that total, since the function for the plan of the year is done

 plan_gral = jovenclub.objects.aggregate(sum=Sum('plan_gral'))
juridic_gral = ingresos.objects.aggregate(sum=Sum('juridico'))
natural_gral = ingresos.objects.aggregate(sum=Sum('natural'))
general = juridic_gral['sum']+natural_gral['sum']
porciento_general = general*100/plan_gral['sum']

would be to adapt those functions to the quarters. How?

    
asked by Roly Miranda Díaz 16.04.2017 в 19:49
source

1 answer

0

Pos thanks to those who helped me ... trying a bit I found the answer.

segundo_trimestre=ingresos.objects.filter(fecha__range=(inicio_segundotrimestre, final_segundotrimestre))
segundo_trimestregral= segundo_trimestre.aggregate(sum=Sum('natural'))
return render_to_response('index.html', {'trimestregeneral':segundo_trimestregral['sum']}

and in the template asi {{segundo_trimestregral}}

    
answered by 17.04.2017 / 22:15
source