[Django]-Django 2.0 Tutorial – AttributeError at /polls/1/vote/ 'ReverseManyToOneDescriptor' object has no attribute 'get'

2👍

This is the line throwing the error:

selected_choice = Question.choice_set.get(pk=request.POST['choice'])

Basically, you need to call choice_set on an instance of the Question model, not on the model itself.

So something like this might work:

question = Question.objects.get(pk=question_id)
selected_choice = question.choice_set.get(pk=request.POST['choice'])

Leave a comment