Answers for "use 0 if value is none in django annotate"

1

django sum get 0 if none

from django.db.models.functions import Coalesce

answers = Answer.objects.filter(<something here>)
                        .annotate(score=Coalesce(Sum('vote__type'), 0))
                        .order_by('-score')
Posted by: Guest on June-12-2020
0

django sum get 0 if none

answers = Answer.objects.filter(<something here>)
                        .annotate(score=Coalesce(Sum('vote__type'), 0))
                        .order_by('-score')
Posted by: Guest on June-12-2020

Code answers related to "use 0 if value is none in django annotate"

Python Answers by Framework

Browse Popular Code Answers by Language