Django

时间:2018-07-02 02:11:47

标签: django

我试图获取'a'和'b'的总和并在每个帖子中显示。但是我得到了错误-'Count'对象没有属性'split'。有人可以帮忙吗?谢谢

def get_queryset(self):
    a = Count('blogger__posts__title')
    b = Count('blogger__posts__likes')

   return (Blog.objects.filter(date__lte=timezone.now())
                                    .order_by('-date')
                                    .annotate(score=Sum(F(a)+F(b),output_field=FloatField()))
            )

2 个答案:

答案 0 :(得分:0)

您可以将其编写如下

def get_queryset(self):
    a = Count('blogger__posts__title')
    b = Count('blogger__posts__likes')
    return (Blog.objects.filter(date__lte=timezone.now())
        .order_by('-date')
        .annotate(s1=a, s2=b)
        .annotate(score=Sum(F('s1')+F('s2'),output_field=FloatField()))
        )

答案 1 :(得分:0)

尝试一下,

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip