Django:QuerySet对象没有属性 [英] Django: QuerySet object has no attribute

查看:1308
本文介绍了Django:QuerySet对象没有属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到一个 AttributeError:'QuerySet'对象没有属性'评级',在我看来,尝试这样做:

I get an AttributeError: 'QuerySet' object has no attribute 'ratings' when trying to do something like this in my view:

def index(request):
    thing_list = Thing.ratings.cumulative_score()
    return render(request, 'index.html', {'thing_list':thing_list})

我的模型:

from ratings.models import Ratings

class Thing(models.Model):
    user = models.ForeignKey(User)
    ...
    rating = Ratings()

使用 django-simple-ratings 应用程序。 链接参考其中 cumulative_score 在该模块中定义。如何使用累积分数?谢谢你的想法!

While using django-simple-ratings app. This link references where cumulative_score is defined in that module. How do I use cumulative score? Thank you for your ideas!

推荐答案

您已经引用评级您的观点,但将经理属性定义为评级(不是')。

You've referenced ratings in your view, but defined the manager attribute as rating (no 's').

这篇关于Django:QuerySet对象没有属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆