The view @login_required def fragebogen(request, code): visitorgroup = get_object_or_none(VisitorGroup, code=code) if not visitorgroup: return HttpResponseRedirect('/fragebogen/?q=invalid') user = request.user FragebogenFormSet = modelformset_factory(FragebogenAnswer, form=FragebogenForm, fields=("answer",), extra=0) FragebogenFormSetOptional = modelformset_factory(FragebogenAnswer, form=FragebogenOptionalAnswerForm, fields=("answer",), extra=0) daten_online_quesion = Question.objects.get(id=91) answers = FragebogenAnswer.objects.filter(user=user) #logging.debug('Answers: %s \n' % answers) if not answers: singleanswer_questions = Question.objects.select_related('choice').filter(category__gte=100, handler__in=[30,31]) for question in singleanswer_questions: answer=FragebogenAnswer() answer.question = question answer.user = user answer.visitorgroup = visitorgroup answer.save() answers = FragebogenAnswer.objects.filter(user=user) if request.method == 'POST': internet_formset = FragebogenFormSet(request.POST, queryset=answers.filter(question__category=100).order_by('-question__ordering'), prefix='internet') games_formset = FragebogenFormSet(request.POST, queryset=answers.filter(question__category=110).order_by('question__ordering'), prefix='games') communities_formset = FragebogenFormSetOptional(request.POST, queryset=answers.filter(question__category=120, question__handler__in=[30,31]).order_by('question__ordering'), prefix='communities') communities_frage_form = FragebogenMultipleAnswersForm(request.POST, question=daten_online_quesion) handy_formset = FragebogenFormSet(request.POST, queryset=answers.filter(question__category=130).order_by('question__ordering'), prefix='handy') interessenform = InteressenForm(request.POST) if internet_formset.is_valid() and games_formset.is_valid()\ and communities_formset.is_valid() and handy_formset.is_valid()\ and interessenform.is_valid() and communities_frage_form.is_valid(): internet_formset.save() games_formset.save() communities_formset.save() handy_formset.save() processMultipleChoiceForm(request, form=communities_frage_form, visitorgroup=visitorgroup) #Verwaltet Datenbankeinträge weg = interesse(interessenform) UserProfile.objects.filter(user=request.user).update(weg=weg) return HttpResponseRedirect('/fragebogen/danke/') else: internet_formset = FragebogenFormSet(queryset=answers.filter(question__category=100).order_by('-question__ordering'), prefix='internet') games_formset = FragebogenFormSet(queryset=answers.filter(question__category=110).order_by('question__ordering'), prefix='games') communities_formset = FragebogenFormSetOptional(queryset=answers.filter(question__category=120, question__handler__in=[30,31]).order_by('question__ordering'), prefix='communities') communities_frage_form = FragebogenMultipleAnswersForm(question=daten_online_quesion) handy_formset = FragebogenFormSet(queryset=answers.filter(question__category=130).order_by('question__ordering'), prefix='handy') interessenform = InteressenForm() The Diff: if request.method == 'POST': - internet_formset = FragebogenFormSet(request.POST, prefix='internet') - games_formset = FragebogenFormSet(request.POST, prefix='games') - communities_formset = FragebogenFormSetOptional(request.POST, prefix='communities') + internet_formset = FragebogenFormSet(request.POST, queryset=answers.filter(question__category=100).order_by('-question__ordering'), prefix='internet') + games_formset = FragebogenFormSet(request.POST, queryset=answers.filter(question__category=110).order_by('question__ordering'), prefix='games') + communities_formset = FragebogenFormSetOptional(request.POST, queryset=answers.filter(question__category=120, question__handler__in=[30,31]).order_by('question__ordering'), prefix='communities') communities_frage_form = FragebogenMultipleAnswersForm(request.POST, question=daten_online_quesion) - handy_formset = FragebogenFormSet(request.POST, prefix='handy') + handy_formset = FragebogenFormSet(request.POST, queryset=answers.filter(question__category=130).order_by('question__ordering'), prefix='handy') interessenform = InteressenForm(request.POST) + if internet_formset.is_valid() and games_formset.is_valid()\ and communities_formset.is_valid() and handy_formset.is_valid()\ and interessenform.is_valid() and communities_frage_form.is_valid(): @@ -121,12 +133,13 @@ def fragebogen(request, code): games_formset.save() communities_formset.save() handy_formset.save() - #processMultipleChoiceForm(request, form=communities_frage_form, visitorgroup=visitorgroup) #Verwaltet Datenbankeinträge + processMultipleChoiceForm(request, form=communities_frage_form, visitorgroup=visitorgroup) #Verwaltet Datenbankeinträge weg = interesse(interessenform) UserProfile.objects.filter(user=request.user).update(weg=weg) - return HttpResponseRedirect('/fragebogen/danke/') + + return HttpResponseRedirect('/fragebogen/danke/')