models.py
class Invoice(models.Model):
Invoice_No=models.AutoField(primary_key=True)
Invoice_Date_Of_Issue=models.DateField(null=False)
Status=models.CharField(max_length=10,null=True)
Discount=models.IntegerField(null=True)
class Invoice_Details(models.Model):
Invoice_Line_No=models.AutoField(primary_key=True)
Invoice_No=models.ForeignKey('Invoice',null=False)
Details=models.CharField(max_length=255,null=True)
Quantity=models.IntegerField(null=False)
Cost=models.FloatField(null=False)
view.py
def index(request):
data=Invoice.objects.all()
form=InvoiceForm(request.POST or None)
if form.is_valid():
save_it=form.save(commit=False)
save_it.save()
data1=Invoice.objects.all()[::-1][:1]
return render_to_response('invoice.html',locals(),context_instance=RequestContext(request))
return render_to_response('invoice.html',locals(),context_instance=RequestContext(re quest))
invoice.html
<form action="" method="post">
<div style="float:right">
</div>
{{ form.as_p }}{% csrf_token %}
<input type="submit" value="Add" name="">
<table id ="myTable">
<h3 align = "center"> Enter Invoice Details Below</h3>
<th>Invoice_Line_No</th>
<th>Invoice_No</th>
<th>Details</th>
<th>Quantity</th>
<th>Cost</th>
<tr>
<td><div contenteditable></div></td>
<td><div contenteditable></div></td>
<td><div contenteditable></div></td>
<td><div contenteditable></div></td>
<td><div contenteditable></div></td>
</tr>
</table>
<button onclick="myFunction()">Add new row</button>
<script>
function myFunction() {
var table = document.getElementById("myTable");
var row = table.insertRow(0);
var cell1 = row.insertCell(0);
var cell2 = row.insertCell(1);
var cell3 = row.insertCell(2);
var cell4 = row.insertCell(3);
var cell5 = row.insertCell(4);
cell1.innerHTML = "<div contenteditable></div>";
cell2.innerHTML = "<div contenteditable></div>";
cell3.innerHTML = "<div contenteditable></div>";
cell4.innerHTML = "<div contenteditable></div>";
cell5.innerHTML = "<div contenteditable></div>";
}
</script>
在我的Invoice addform页面中......提交..我必须为用户创建一个可编辑的表来插入Invoice_details记录。对于相同的Invoice_No,可以有多个Invoice_details.Using Javascript我可以在用户单击添加新行按钮时创建新行。但我不知道如何从invoice.html(可编辑的表格字段)中检索数据到视图并将其保存在数据库中。
任何人都可以帮我解决这个问题吗?
提前致谢。