django sum get 0 if none

Solutions on MaxInterview for django sum get 0 if none by the best coders in the world

showing results for - "django sum get 0 if none"
Gaia
15 Jun 2017
1from django.db.models.functions import Coalesce
2
3answers = Answer.objects.filter(<something here>)
4                        .annotate(score=Coalesce(Sum('vote__type'), 0))
5                        .order_by('-score')
Gillian
03 Mar 2017
1answers = Answer.objects.filter(<something here>)
2                        .annotate(score=Coalesce(Sum('vote__type'), 0))
3                        .order_by('-score')