from django.db.models import Sum, DecimalField
from django.db.models.functions import Cast

Model.objects.annotate(deci_con_factor=Cast('conversion_factor', 
DecimalField()).aggregate(sum=Sum('deci_con_factor')).get('sum')

You need to change your char type to decimal type , you can use CAST 
operator, you will cast you charfield to decimal field and annotate it on 
every object then use that annotated field in aggregate func. 

On Sunday, 13 June 2021 at 15:38:05 UTC+5:30 sebasti...@gmail.com wrote:

> Hello,
>
> i think this is the right answer:
>
> from django.db.models import Sum
>
> ModelName.objects.filter(field_name__isnull=True).aggregate(Sum('field_name'))#
>  returns {'field_name__sum': 1000} for example
>
>
> Am So., 13. Juni 2021 um 12:04 Uhr schrieb www.forum-gh.com <
> lada...@gmail.com>:
>
>> Hello friends 
>> please i have: conversion_fqctor = models.charfield(choices=FACTOR)
>>
>> i want to sum the conversion_factor inside my view.py how do i convert it 
>> to a decimal and use the Sum()
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/CALYpPT8_5sMsyjzvpdGZ3gBQbqiwQW7EHgZ61i4LdLQ1z38LYg%40mail.gmail.com
>>  
>> <https://groups.google.com/d/msgid/django-users/CALYpPT8_5sMsyjzvpdGZ3gBQbqiwQW7EHgZ61i4LdLQ1z38LYg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1eff5efd-0d61-4d5d-8dca-1cbdd7aa4a85n%40googlegroups.com.

Reply via email to