fix kb entry sorting

master
Alice 5 years ago
parent ee123a455b
commit 0bf3ed05c2

@ -1,5 +1,6 @@
from django.db import models
from django.db.models.aggregates import Sum
from django.db.models.functions import Coalesce
from django.conf import settings
from django.urls import reverse
from django.template.loader import render_to_string
@ -101,8 +102,8 @@ class KbEntry(models.Model):
class KbEntryManager(models.Manager):
def get_top(self, n, **kwargs):
return (self.filter(internal=False, **kwargs)
.annotate(Sum('vote_set__vote'))
.order_by('-vote_set__vote__sum')
.annotate(score=Coalesce(Sum('vote_set__vote'), 0))
.order_by('-score', 'id')
[:n])
objects = KbEntryManager()

Loading…
Cancel
Save