我正在建立一个问答网站并在模板上列出问题。我正在使用 django-voting 对列表中的每个问题进行上/下投票,并且我想按票数从高到低的顺序显示问题。
我将 Django Generic Aggregation 添加到我的应用程序中,并收到此错误:
'GenericForeignKey' object has no attribute '_default_manager'
怎么了?
这是我的模型:
#models.py
class Question(models.Model):
movie = models.ForeignKey(Movie, blank=True, null=True)
question_text = models.CharField(verbose_name = "Question", max_length = 100)
q_pub_date = models.DateTimeField(auto_now_add = True)
q_author = models.ForeignKey(User)
风景:
#views.py
def questions(request, movie_id):
p = Movie.objects.get(pk=movie_id)
k = Question.objects.filter(movie = p).order_by('-q_pub_date')
top = generic_annotate(k, Vote.object, Sum('vote'))
return render_to_response('qanda/questions.html',
{'the_question':top}
context_instance = RequestContext(request))
还有我的模板(没有投票表格就删掉了):
#questions.html
{% for question in the_question %}
<p>{{ question.question_text }}
{% endfor %}
如何摆脱此错误并以正确的顺序显示问题?