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 trialChristopher Gunawan
10,754 PointsWhat is the purpose of using QUERYSET when initializing the formset?
@login_required
def answer_form(request, question_pk):
question = get_object_or_404(models.Question, pk=question_pk)
formset = forms.AnswerFormSet(queryset=question.answer_set.all())
if request.method == 'POST':
formset = forms.AnswerFormSet(request.POST, queryset=question.answer_set.all())
if formset.is_valid():
answers = formset.save(commit=False)
for answer in answers:
answer.question = question
answer.save()
messages.success(request, "Added answers")
return HttpResponseRedirect(question.quiz.get_absolute_url())
return render(request, "courses/answer_form.html", {'question': question, 'formset': formset})
What is the purpose of using QUERYSET when initializing the formset?
Any help would be much appreciated. Thank you!
Christopher Gunawan
10,754 PointsChristopher Gunawan
10,754 PointsI receive the same HTML output with or without the query set in this case