2009-08-09 4 views
0

메신저 다시 묻습니다 :) 나는 이것을 어떻게 만드는지 모른다.Django가 유효성을 검사하고 미리보기 URL로 돌아갑니다?

내 영어가 너무 좋지 않아,하지만 병이 요청하려고 :

방법 병 유효성 검사 양식을 다시 미리보기 URL (동일한보기 양식)에 가서이 요청하는 유효성 검사 오류? 메신저를 표시 왜냐하면 내가 2 양식을 가지고 첫 번째 양식의 행동은 두 번째 양식 (POST)로 가고 있지만이 두 번째 양식 (보기?) 나는 첫 번째 양식을 유효하게 할 필요가 있다면 첫 번째 양식이 유효하다면 나는 두 번째 양식을 보여주고 싶다. 그렇지 않으면 오류가있는 첫 번째 양식이 표시됩니다.

나는 분명히, 나 미안해.

def secondForm(request): 
    if request.method =='POST': 
     form = FirstForm(request.POST) 
     if form.is_valid(): 
      fields = request.POST.copy() 
      # showing the second form?? with x differents fields, i have 2. 
      if fields['xvalue']=='1': # this is from radio buttons 
      form2 = xSecondForm() 
      elif fields['xvalue']=='2': 
      form2 = ySecondForm() 
     else: 
     # here go back with erros msgs???? 
     #return render_to_response('firstFormTemplate.html',{'form': form}, context_instance=RequestContext(request)) 
    else: 
     #return something or go back ??? 

감사들에게 PD를 : 이것에 대해 생각

메신저 코딩 행복, 인스턴트 메신저 장고 + 파이썬 : D

답변

3

예, formwizard가 답이 될 수 있지만보기의 일부 논리로이를 수행 할 수 있습니다. 같은

뭔가 :

def your_view(request): 
    context = {} 
    data = request.method == 'POST' and request.POST or None 
    form = FirstForm(data=data) 
    # If the first form is valid, build the second. 
    if form.is_valid(): 
     if form.cleaned_data['xvalue'] == 1: 
      form2 = xSecondForm(data=data) 
     else: 
      form2 = ySecondForm(data=data) 
     context['form2'] = form2 
    # If both forms are valid, everything is done. 
    if form.is_valid() and form2.is_valid(): 
     # TODO: put save/processing logic here 
     # Now redirect. 
     return http.HttpResponseRedirect(...) 
    # If we get here, either there hasn't been a post yet, the second form hasn't 
    # been entered, or there was an error in either form. 
    context['form'] = form 
    return render_to_response(...) 
0

좋아, 얘들 아, 내가 마일 솔루션 FormWizard하고 있다고 생각 :)

하지만 두 번째 양식에 대한 내용이 명확하지 않습니다. 라디오에서 선택된 옵션이 두 번째 양식의 필드가 더 많거나 적은 경우 두 번째 양식을 다른 방식으로 표시해야하기 때문에

; (

0

나는 당신이 두 번째 형태의 디스플레이를 무슨 방법 /에 대한 몇 가지 논리를 할 process_step()를 사용하려는 생각합니다.