我需要一些帮助。在我的表单中,我设置+按钮,然后单击自动生成一个新的文本框。现在如何使用django将新文本框的数据存储在mysql中?
请帮助我找出... 预先感谢。.
models.py
class Rows(models.Model):
service=models.TextField(default='',max_length=200)
item=models.TextField(default='',max_length=200)
def __str__(self):
return self.service
add1.html
<body>
<div class="col-sm-2">
<form method="post" action="">
{% csrf_token %}
<table id="myTable" class=" table order-list" >
<tbody>
<tr>
<th>
<label for="id_service" name="service">Services Provided</label>
</th>
<td>
<textarea name="service" maxlength="500" required id="id_service"></textarea>
</td>
<td colspan="5" style="text-align: left;">
<input type="button" class="btn-sm-2 pull-right btn btn-success" id="addrow" value="+"/>
</td>
</tr>
</tbody>
</table>
<table id="Table" class=" table order-type">
<tbody>
<tr>
<th>
<label for="id_item" name="item">Awards</label>
</th>
<td>
<textarea name="item" maxlength="500" required id="id_item"></textarea>
</td>
<td colspan="5" style="text-align: left;">
<input type="button" class="btn-sm-2 pull-right btn btn-success" id="addaward" value="+" />
</td>
</tr>
</tbody>
</table>
<button type="submit" >submit</button>
</form>
<a href="{% url 'work:add' %}">
</a>
</div>
</body>
<script>
$(document).ready(function () {
var counter = 0;
$("#addrow").on("click", function () {
var newRow = $("<tr>");
var cols = "";
cols += '<td><input type="text" class="form-control" name="service' + counter + '"/></td>';
newRow.append(cols);
$("table.order-list").append(newRow);
counter++;
});
});
$(document).ready(function () {
var counter = 0;
$("#addaward").on("click", function () {
var newRow = $("<tr>");
var cols = "";
cols += '<td><input type="text" class="form-control" name="item' + counter + '"/></td>';
newRow.append(cols);
$("table.order-type").append(newRow);
counter++;
});
});
</script>
</html>
这是我的表格
单击+按钮时会自动生成一个新列。我如何将新测试箱上的数据存储到mysql数据库