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')
4
2
answers = Answer.objects.filter(<something here>)
.annotate(score=Coalesce(Sum('vote__type'), 0))
.order_by('-score')
Thank you!
2
0
Are there any code examples left?
New code examples in category Python