0

我想根据用户检查的输入在我的 Logofsupport 数据表中创建一个新行,也许我正在处理这个错误的 wat,但我想获取一些 innerHTML 并将其插入服务器名和根名,然后拉出日期这应该很容易,并且基于下拉菜单选择一个将附加到操作字段的操作,然后提交数据,这基本上是我相信 django 的保存功能。

 def log(request):
     cust = Logofsupport.objects.create(servername= "innerHTML FIELD",rootname="innerHTML
                 FIELD", requesteddate="innerHTML FIELD", action="Submit Form FIELD")

    return render_to_response('status/log.html', {'add':cust},context_instance=RequestContext(request))

这是我的 HTML 我想检查该行并根据检查是否为真抓取根名称、请求日期和基于下拉框值的操作,然后在提交按钮后创建一个新行以添加到我的 sql 表中已被点击。我对如何创建表单代码更感兴趣。


  <body>
<div id="container">
    <div id = "left" >
        {%for status in root|slice:":1" %}
    <h1><center>Root List by {{status.rootgroup}} Rootgroup<center></h1>
    {% endfor %}
        <h3 id="time">current:  </h3>
        <table border = "2">

            <tr>
            <th><input type="checkbox" id="selectall"/>   Check All</th>
                <th>Rootname </th>
                <td>Urls</td>
                <th> custs </th>
                <th> jvmms </th>
                <th> x64 </th>
                <th> currentplatform </th>
                <th> currentjdk </th>
                <th> currenttomcat </th>
                <td><p>Date: <input type="text" id="datepicker" size="10" /></p></td>
        <td><input type="text" value="12:00" size="5" /><td>
            <select name="ampm">
                <option value="am">AM</option>
                <option value="pm">PM</option>
            </select>
            </tr>
                {% for status in root %}
            <tr id="l{{forloop.counter}}">
            <form name= "info" action="">
            <td align="center"><input type="checkbox" class="selectedId" onclick="resetSelectedAll(this);" id="row{{ forloop.counter }}" ></td>
                <td id="row{{forloop.counter}}rootname">{{ status.rootname }}</td>
                <td id="row{{forloop.counter}}urls">{{ status.urls }}</td>
                <td id="row{{forloop.counter}}custs">{{ status.custs }}</td>
                <td id="row{{forloop.counter}}jvmms"> {{ status.jvmms }}</td>
                <td id="row{{forloop.counter}}x64">{{ status.x64 }}</td>
                <td id="row{{forloop.counter}}currentplatform"> {{ status.currentplatform }}</td>
                <td id="row{{forloop.counter}}currentjdk"> {{ status.currentjdk }}</td>
                <td id="row{{forloop.counter}}currenttomcat">{{ status.currenttomcat }}</td>
            </tr>

                {% endfor %}

        </table>
        <select name="buttons">
            <option value="Restart">Restart</option>
            <option value="Full_Dump">Full_Dump</option>
            <option value="Redeploy">Redeploy</option>
            <option value="Thread">Thread</option>
            </select>
            <input type="submit" onclick="check()" value="submit"/>
    </form>

    </div>

这是我创建一个使用复选框的表单的尝试,希望它可以更容易地创建一个新行,我有点迷茫。


class LogofsupportForm(forms.ModelForm):
    myboolean = forms.BooleanField()
    servername = forms.CharField(max_length=50) # Field name made lowercase.
    rootname = forms.CharField(max_length=50) # Field name made lowercase.
    requesteddate = forms.DateTimeField() # Field name made lowercase.
    action = forms.CharField(max_length=50) # Field name made lowercase.
    loginname = forms.CharField(max_length=50) # Field name made lowercase.
    result = forms.CharField(max_length=50) # Field name made lowercase.
    class Meta:
        model= Logofsupport
        fields = ['servername', 'rootname', 'requesteddate', 'action','loginname',
                  'result']
4

1 回答 1

0

如果我正确理解您的问题:如果您想使用 django.forms 来验证您发布的数据,您需要为 HTML 表单输入字段提供唯一名称。由于您要发布的数据不在 HTML 输入字段中,因此我建议您使用 javascript 提取值并通过 AJAX 发布,例如 jQuery.post()。

于 2013-07-15T16:44:22.163 回答