Django: QuerySet object has no attribute

放肆的年华 提交于 2019-12-11 15:03:10

问题


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})

My model:

from ratings.models import Ratings

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

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!


回答1:


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



来源:https://stackoverflow.com/questions/14211551/django-queryset-object-has-no-attribute

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!