0
私は複雑な形を持っている:ジャンゴ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も成長する可能性が少なくとも2 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' ボタン、および '送信' ボタンがあります。
- views.pyファイルでデータを収集するにはどうすればよいですか?適切なモデル
- に保存するために、このようなダイナミックなフォームからデータを収集する良い方法はありますか?
ありがとう!