我试图在Django中完成一个简单的应用程序,我需要在模态窗口中显示一些数据集,更新它然后保存。到目前为止,我能够在模态窗口中显示所选数据,但我的更改不会保存。点击'保存'按钮窗口关闭很好,但更改不会反映在数据库中。 href位于一个文件中,如下所示:
<ul>
{% for n in items %}
{% if n.status_id != 7 %}
task:{{ n.task_id }}
<li><a href="{% url 'cables.views.add_cycle' id=n.task_id %}" id="link" class="btn btn-default"
type="button" data-toggle="modal" data-target="#myModal">{{ n.task.sachnr.sachnr }}</a>
start: {{ n.date_start }} status: {{ n.status.status_set.last.status }} </li>
{% endif %}
{% endfor %}
</ul>
<div id="myModal" class="modal fade" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
</div>
</div>
链接所遵循的其他文件(add_cycle.html)文件如下所示:
{% block content %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="" enctype="multipart/form-data" method="post" class="upload">
{% csrf_token %}
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">some header</h4>
<ul>
<li>sachnr {{ new_cycle.sachnr.sachnr }}</li>
<li>status: {{ new_cycle.status_set.last.status }} od: {{ new_cycle.status_set.last.date_start }} </li>
</ul>
<input id="id_status_set-TOTAL_FORMS" name="status_set-TOTAL_FORMS" type="hidden" value="1">
<input id="id_status_set-INITIAL_FORMS" name="status_set-INITIAL_FORMS" type="hidden" value="0">
<input id="id_status_set-MIN_NUM_FORMS" name="status_set-MIN_NUM_FORMS" type="hidden" value="0">
<input id="id_status_set-MAX_NUM_FORMS" name="status_set-MAX_NUM_FORMS" type="hidden" value="2">
<p>
<label for="id_status_set-0-status">new status:</label>
<select id="id_status_set-0-status" name="status_set-0-status">
<option value="" selected="selected"></option>
{% for n in statuslist %}
<option value={{ n.id }}>{{ n.name }}</option>
{% endfor %}
</select>
<input id="id_status_set-0-task" name="status_set-0-task" type="hidden" value="{{ new_cycle.id }}">
<input id="id_status_set-0-id" name="status_set-0-id" type="hidden" value="{{ status.id }}">
</p>
<div class="modal-footer">
<button class="btn btn-default" type="submit">save</button>
<a href="{% url 'cables_new_task' %}" type="button" class="btn btn-default">cancel</a>
</div>
</div>
</div>
</div>
</form>
</body>
</html>
{% endblock %}
当我在没有模态窗口的情况下编辑记录但使用一个在新标签页中打开数据的简单链接时,一切正常。
答案 0 :(得分:0)
你是对的,我在形式上缺少行动。它应该类似于action =&#34; {%url&#39; cables_add_cycle&#39; new_cycle.id%}&#34;。添加后,它工作得很好。