是否可以创建一个表单,修改何时在数据库中找到信息,或者如果数据库中没有任何内容,则添加信息?
所以我有一个模板,允许我显示值,如果在字段中有一个给出字段或答案然后显示答案的空白字段.
我的formset模板:
<form method="POST" action="">
{{ formset.management_form }} {% csrf_token %}
<table>
<!-- <br>{{ formset.as_table }}<br> -->
{% for question in questions %}<hr>
<label for="question">{{ question }} [{{ question.id }}]</label>
<input type="hidden" id="id_form-{{ forloop.counter0 }}-question" name="form-{{ forloop.counter0 }}-question" value="{{ question.id }}"/>
</p>
{% if question.reply_set.all %}
{% for reply in question.reply_set.all %}
<p>
<label for="answer">Réponse :</label>
<input type="text" id="id_form-{{ forloop.parentloop.counter0 }}-answer" name="form-{{ forloop.parentloop.counter0 }}-answer" value="{{ reply.answer }}"/>
</p>
{% endfor %}
{% else %}
<p>
<label for="answer">Réponse :</label>
<input …Run Code Online (Sandbox Code Playgroud)