我正在使用django-voting包,并一直试图让它的经理 get_top() 工作。我偶然发现了一个问题——它产生了生成器(实际上我需要从中提取数据以从数据库中选择项目),这对我来说似乎是个问题。
在花了两天的谷歌搜索和阅读论坛之后,我最接近的想法是: django 中的“生成器对象”是什么?
它说任何生成器都可以通过以下方式转换为列表:
mylist=list(myGenerator)
虽然如果我将生成器转换为列表,我会收到以下错误:
'NoneType' object has no attribute '_meta'
这是我的视图和模型代码:
def main(request):
temporary = TopIssue.objects.get_top(Model=Issue, limit=10)
temp_list = list(temporary)
return render_to_response('main/index.html', temp_list)
from voting.managers import VoteManager
class TopIssue:
objects = VoteManager()
有任何想法吗?