5👍
✅
You can use an ExpressionWrapper
[Django-doc] here to set this to a FloatField
[Django-doc] or DecimalField
:
from django.db.models import ExpressionWrapper, FloatField
ratings = Application.objects.filter(id=review.id).annotate(
rate=ExpressionWrapper(
(F('col_1')+F('col_2')+F('col_3')+F('col_4')+F('col_5')+F('col_6'))/6,
output_field=FloatField()
)
)
Depending on the situation, it might be better to use a FloatField
or a DecimalField
[Django-doc].
Source:stackexchange.com