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')
1answers = Answer.objects.filter(<something here>)
2 .annotate(score=Coalesce(Sum('vote__type'), 0))
3 .order_by('-score')