I\'m trying to get a division between two annotate results in queryset. Impression is much larger than click, so I should get tenth decimal.
def get_queryset(se
As far as I am aware, there isn't a way to do this using the ORM.
The Sum()
function returns the same field type as put into it (i.e. an IntegerField() will always return an Integer). You could use a function like ExpressionWrapper
to force the output to be a float, but that won't help in this case as it will be too late: the division of two integers will have been already returning another integer.
To solve your problem, remove the ctr_monthly
section form your query, and create a simple template tag which converts the two numbers to floats and divide them.
Your template will then look like:
{{ monthly_ctr(googleData.click, googleData.impression) | floatformat:2}}