[Solved]-Django's annotate Count with division returns integer instead of float

23👍

Full answer following @Alasdair’s comment:

from django.db.models import FloatField
from django.db.models.functions import Cast

qs = MyModel.objects.order_by('name').values('name').annotate(
    count=Cast(Count('name') / 2.0, FloatField()))
👤Udi

Leave a comment