def add_choices(question_pk, choice_words): """ Aug 13, 2015 Isaac's :return: """ question = Question.objects.get(pk=question_pk) for index, choice_word in enumerate(choice_words): number = index+1 choice = Choice(text=choice_word, number=number, question=question) choice.save() reset_question(question)
def add_choices(question_pk, choice_words): """ Aug 13, 2015 Isaac's :return: """ question = Question.objects.get(pk=question_pk) for index, choice_word in enumerate(choice_words): number = index + 1 choice = Choice(text=choice_word, number=number, question=question) choice.save() reset_question(question)
def post(self, request, slug): question = Question.objects.get(pk=slug) question_form = QuestionForm(request.POST, prefix=slug, instance=question) choice_forms = [ChoiceLimitedForm(request.POST, prefix=choice.pk, instance=choice) for choice in Choice.objects.filter(question=question)] if question_form.is_valid() and all(form.is_valid() for form in choice_forms): question_form.save() for form in choice_forms: form.save() reset_question(question) return redirect(request.POST['next']) else: kwargs = {'slug': slug} data = {'title': 'Failure', 'message': 'Question update failed.', 'link': reverse('questions-update', kwargs=kwargs), 'linkdes': 'Go back to update page.',} return render(request, 'result.html', data)