1

I'm building a Q&A site and listing out the questions on a template. I'm using django-voting to up/down vote on each question in the list, and I want to display the questions in order of number of votes, highest to lowest.

I added Django Generic Aggregation to my app, and am getting this error:

'GenericForeignKey' object has no attribute '_default_manager'

What's wrong?

Here's my model:

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

The view:

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

And my template (stripped down without the voting forms):

#questions.html
{% for question in the_question %}
    <p>{{ question.question_text }}
{% endfor %}

How do I get rid of this error and display the questions in the right order?

Jacinda
  • 4,932
  • 3
  • 26
  • 37
Chris Yin
  • 761
  • 1
  • 11
  • 23

0 Answers0