1
複数のフォームに1つのモーダルを使用する方法を理解できません。djangoで複数のフォームに1つのモーダルを使用していますか?
今、私は作成したいseveralsフォームのための1つだけのモーダルを持つ方法を見つけることができません。私は提出しようとしている30の書式のためのhtmlの30のモーダルを本当に望んでいません。
自動的に入力する別の方法はありますか?
私のモデルはその後
class Project(models.Model):
project_name = models.CharField(max_length=30)
project_status = models.IntegerField(choices=PROJECT_STATUS,default=1)
project_sponsor = models.CharField('Project Sponsor',
max_length=255,default=1)
scope = models.TextField(max_length=10240, blank=True)
description = models.TextField(max_length=10240, blank=True)
ですが、私は各モデル属性に1つのフォームを持っていると思いました。例えば、私が説明するためのフォーム、スコープの後、別のものを持っているしたいと思います...
class ScopeForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(ScopeForm, self).__init__(*args, **kwargs)
for field in self.fields:
self.fields[field].required = False
class Meta:
model = Project
fields = ['project_scope',]
class DescriptionForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(DescriptionForm, self).__init__(*args, **kwargs)
for field in self.fields:
self.fields[field].required = False
class Meta:
model = Project
fields = ['description',]
私のhtmlファイルで、私は、フォーム
<a href="#" data-toggle="modal" data-target="#purpose">Purpose</br></a>
<div class="modal fade" id="purpose" tabindex="-1" role="dialog" aria-labelledby="modalLabel" aria-hidden="true">
<div class="modal-dialog">
\t <div class="modal-content">
\t \t <div class="modal-header">
\t \t \t <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button>
\t \t \t <h3 class="modal-title" id="lineModalLabel">Purpose</h3>
\t \t </div>
\t \t <div class="modal-body">
\t \t \t <form>
<div class="form-group">
<label>
The Purpose will provide a brief overview of the purpose of the project and provide enough of a description to complete
the following sections. If information to complete the following sections is not available, state that it is unavailable and
state the person accountable and schedule for completion. </label>
</div>
<div class="form-group" "width: 300px" "height: 100px" "border: 1px solid blue">
<label for="purpose">Purpose</label>
<textarea id="txtCommentHere" class="form-control" rows="3" id="purpose" placeholder="Purpose">
</textarea>
</div>
<div class="checkbox">
<label>
<input type="checkbox"> Draft
</label></br>
<label>
<input type="checkbox"> In Progress
</label>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
\t \t </div>
</div>
</div>
</div>
[データをブートストラップモーダルに渡す]の可能な複製(http://stackoverflow.com/questions/10626885/passing-data-to-a-bootstrap-modal) – Selcuk