Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Django Forms Inlines and Media Inline Model Formset

answer.question = question in 'create_question' view

In answer.question = question, where is the 'question' coming from in 'create_question' view

1 Answer

Steven Parker
Steven Parker
231,269 Points

I assume you're asking about line 131 in "learning_site/courses/views.py", and you can see where "question" is created and assigned in the first statement of "answer_form" on line 120:

    question = get_object_or_404(models.Question, pk=question_pk)

I get where the question is coming from in line 120, but it is also used in line 94 in 'create_question' view; where are we getting that 'question' from? Also, for none of the forms, the 'action' field is specified, so how does the form knows which view to go to when we hit the save or button??

Steven Parker
Steven Parker
231,269 Points

Oh, I see. I was looking at a different point in the video.

The "question" in "create_question" is created on line 89:

            question = form.save(commit=False)

When no action is specified, the browser just refreshes the current page on submit.