django模型使用json或任何其他方法保存表如何在后端保存

时间:2018-10-18 07:27:40

标签: json django django-models django-views

这是我的html代码,我想将此表保存在Django数据库中,但不知道该怎么做,我的意思是如何保存在模型中,我认为json是可以听到的,但我不早点将json用于django

models.py

class Mvouchar(models.Model):
        related = models.ForeignKey(Signs, on_delete=models.CASCADE, null=True, blank=True)
        bill_no = models.CharField(max_length=80, null=True, blank=True)
        bill_details = models.CharField(max_length=1000, null=True, blank=True)
        am = models.CharField(max_length=30, null=True, blank=True)
views.py
    def mvouchar(request):
                if request.method == "POST":
                    userdata = User.objects.get(username = request.user)
                    accountdata = Signs.objects.get(relation_id=userdata.id)
                    b_no = request.POST['billno']
                    b_details = request.POST['billdetails']
                    at = request.POST['amount2']

.css:

table {
    width:50%;
    align: center;
}
table, th, td {
    border: 1px solid black;
    border-collapse: collapse;
}
th, td {
    padding: 12px;
    text-align: left;
}
table#t01 tr:nth-child(even) {
    background-color: #eee;

}
table#t01 tr:nth-child(odd) {
   background-color: #fff;
}
table#t01 th {
    background-color: grey;
    color: white;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
    <script src="jquery-1.10.2.js"></script>
<script> var i = parseInt(0);
        var sum = parseInt(0);
        $(document).ready(function () {

            var i = parseInt(0);
            $("#Button1").click(function () {
                var name1 = $("#billNo").val();
                var name2 = $("#billDetails").val();
                var name3 = $("#amnt").val();
                sum += parseInt(name3);
                var markup = "<tr id='" + i + "'><td>" + name1 + "</td><td>" + name2 + "</td><td>" + name3 + "</td><td><input id='Button" + i + "' type='button' value='Edit' onclick='Edit(" + i + ")'/> <input id='Button244' type='button' value='Delete' onclick='deleteRow(" + i + ")'/></td></tr>";
                i++;
                $("table tbody").append(markup);
                $('table tbody:last-child').append('<tr>...</tr><tr>...</tr>');

                $("#total").text(sum);
            });
            $("#Button").click(function () {
                $("#'" + i + "'").remove(rowid);
            });


            $(".btnEdit").bind("click", Edit);
        });
        function deleteRow(rowid) {
            if (confirm("Do you want to delete: " + name)) {
                var aa = $("#" + rowid).find("td:eq(2)").text();
                sum -= parseInt(aa);
                $("#" + rowid).remove();
                $("#total").text(sum);

            }
        }
        function Edit(rowid) {
            var par = $(this).parent().parent(); //tr 
            var aa = $("#" + rowid).find("td:eq(2)").text();
            var bb = sum;
            var bil = $("#" + rowid).find("td:eq(0)").text();
            var acc = $("#" + rowid).find("td:eq(1)").text();
            var amt = $("#" + rowid).find("td:eq(2)").text();
            $("#" + rowid).find("td:eq(0)").html("<input type='text' id='txtName1' value='" + bil + "'/>");
            $("#" + rowid).find("td:eq(1)").html("<input type='text' id='txtName2' value='" + acc + "'/>");
            $("#" + rowid).find("td:eq(2)").html("<input type='text' id='txtName3' value='" + amt + "'/>");
            $("#Button" + rowid).val("Save");
            $("#Button" + rowid).attr("onclick", "Save(" + rowid + ")");
        };
        function Save(rowid) {
            $("#" + rowid).find("td:eq(0)").text($("#txtName1").val());
            $("#" + rowid).find("td:eq(1)").text($("#txtName2").val());
            $("#" + rowid).find("td:eq(2)").text($("#txtName3").val());

            $("#Button" + rowid).val("Edit");
            $("#Button" + rowid).attr("onclick", "Edit(" + rowid + ")");
            var table = $("table tbody");
   table.find('tr').each(function (i, el) {
        var $tds = $(this).find('td'),
             Quantity = $tds.eq(2).text();
    });
    var rows = $('table tbody').length;
        };
var table = $("#mprDetailDataTable table tbody");
   table.find('tr').each(function (i, el) {
        var $tds = $(this).find('td'),
            productId = $tds.eq(0).text(),
            product = $tds.eq(1).text(),
            Quantity = $tds.eq(2).text();

    });
    $("#Button1").click(function(){
         tempResult.val(tempResult.val()+ total);
         $("#totalAmount").val(total);
        $("#amount_string").val(convertNumberToWords($("#totalAmount").val()));    
    });    </script>
 Bill No: <input type="text" name="billno" id="billNo" autocomplete="off">
            Amount: <input type="text" name="amount2" id="amnt" pattern="[0-9]+" title="please enter amount" autocomplete="off">
            <br>
            Bill Details: <input type="text" id="billDetails" name="billdetails" autocomplete="off">
            <button type="button" id="Button1" class="button" value="Add">Add</button>
            <button type="button" id="btn2" class="button" value="Complete all entries">Complete All entries</button>
            <br>   
<table align="center">
  <thead>
   <tr>
     <th>Bill No</th>
     <th>Bill Details</th>
     <th>Amount</th>
     <th>Action</th>
   </tr>
  </thead>
  <tbody>
  </tbody>
  <tfoot>
    <tr>
      <td></td>
      <td></td>
      <td></td>
      <td>Total : <span id="total"></span></td>
    </tr>
   </tfoot>
 </table>

1 个答案:

答案 0 :(得分:1)

PSExec64.exe