0

는 I 복잡한 형태를 갖는다 :장고 Dyanmic 형태 : 프리젠 테이션 정보 수집

<<forms.py>> 
class AttributeOptionForm(forms.Form): 
    option_name = forms.CharField(label="Attribute Option") 


class AttributeForm(forms.Form): 
    attr_name = forms.CharField(max_length=100, label="Attribute Name") 
    attr_options_list = [AttributeOptionForm(), AttributeOptionForm()] 


class ProjectForm(forms.Form): 
    name = forms.CharField(max_length=250, label="Name") 
    attr_form_list = [AttributeForm()] 

ProjectFrom은 (런타임에서 성장할 수있다) 적어도 하나 AttributeForm 보유 각각 AttributeForm (또한 어떤 성장할 수 적어도 두 AttributeOptionForm 보유 런타임시). 어떤 AttributeForm도 여러 답변 (AttributeOptionForm)이있는 질문으로 생각하면됩니다.

이렇게하면 ProjectForm을 어떻게 표현할 수 있습니다. 형태

<<project_form.html>> 
         <form class="form-horizontal" action="" method="post" enctype="multipart/form-data"> 
         {% csrf_token %} 
         <div class="form-group"> 
          <div class="col-sm-offset-2 col-sm-10"> 
           <span class="text-danger small">{{ form.name.errors }}</span> 
          </div> 
          <label class="control-label col-sm-2">{{ form.name.label_tag }}</label> 
          <div class="col-sm-9">{{ form.name }}</div> 
         </div> 
         {% for attr_form in form.attr_form_list %} 
         <div class="form-group"> 
          <div class="col-sm-offset-2 col-sm-10"> 
           <span class="text-danger small">{{ attr_form.att_name.errors }}</span> 
          </div> 
          <label class="control-label col-sm-2">{{ attr_form.attr_name.label_tag }}</label> 
          <div class="col-sm-9">{{ attr_form.attr_name }}</div> 
          {% for option in attr_form.attr_options_list %} 
           <div class="col-sm-offset-2 col-sm-10"> 
            <span class="text-danger small">{{ option.option_name.errors }}</span> 
           </div> 
           <label class="control-label col-sm-2">{{ option.option_name.label_tag }}</label> 
           <div class="col-sm-9">{{ option.option_name }}</div> 
          {% endfor %} 
         </div> 
         {% endfor %} 
        </form> 

는 또한, 'add_attribute_option'버튼 (속성마다) 'ADD_ATTRIBUTE'버튼 및 '제출'버튼이있다.

  1. 어떻게하면 내 views.py 파일에서 데이터를 수집합니까? 해당 모델을 저장하려면
  2. 이와 같이 동적 양식에서 데이터를 수집하는 더 좋은 방법이 있습니까?

고마워요!

답변