這應該很簡單,我實際上昨天已經開始工作了。我不知道什麼改變了,但現在拋出一個錯誤。Django Inline Formset問題(列表超出範圍)
def game_design(request):
user=User.objects.get(pk=request.user.id)
organization=user.organization_set.all()[0]
website=organization.website_set.all()[0]
surveys=website.survey_set.all()
error=''
SurveyFormSet=inlineformset_factory(Website, Survey, extra=0, can_delete=True)
NavigationFormSet=modelformset_factory(Navigation, extra=1)
if request.method=='POST':
survey_formset=SurveyFormSet(request.POST, request.FILES, prefix="surveys")
navigation_formset=NavigationFormSet(request.POST, request.FILES, prefix="navigations")
if survey_formset.is_valid() and navigation_formset.is_valid():
survey_formset.save()
navigation_formset.save()
return HttpResponseRedirect("/rewards/")
else:
error="Please fix your errors"
survey_formset=SurveyFormSet(request.POST, request.FILES,prefix="surveys")
navigation_formset=NavigationFormSet(request.POST, request.FILES,prefix="navigations")
return render_to_response('website/game_design.html', {'website':website,'survey_formset':survey_formset, 'navigation_formset':navigation_formset, 'error':error}, context_instance=RequestContext(request))
else:
survey_formset=SurveyFormSet(instance=website,prefix="surveys")
navigation_formset=NavigationFormSet(queryset=Navigation.objects.none(),prefix="navigations")
return render_to_response("website/game_design.html", {'website':website,'survey_formset':survey_formset,'navigation_formset':navigation_formset,'error':error},context_instance=RequestContext(request))
感謝在這一個
這裏的縮進錯誤在代碼中不存在。在我檢查POST方法後,錯誤似乎在行中被拋出。我想這可能是一個模板錯誤,但我用{{form.as_p}}和現有的調查顯示正確 – Ben 2011-02-18 03:08:52