提交不适用于使用updateview手动呈现的django 2.1模型表单

时间:2018-10-23 22:40:24

标签: django

完全是django的新手。

我有一个modelform,并已使用form字段手动对其进行了渲染,以便可以与CSS一起使用,但是,如果使用form.as_p似乎可以保存我的数据,如果我使用手动进行form渲染并提交,则什么也没有保存并想知道 1)为什么form.as_p可以工作,而我的自定义表单字段却无法工作 2)更新视图类,是否需要post方法?

class CompanyUpdateView(UpdateView):
    template_name = 'inservice/company_update.html'
    form_class = CompanyForm
    model = CompanyInfo


    def get_object(self):
        pk_=self.kwargs.get("pk")
        return get_object_or_404(CompanyInfo,pk=pk_)


company_update.html
<form method="POST" action="">
    {% csrf_token %}


    <div class="container-fluid">
            <div class ="row mb-5">
                <div class="col">
                    <div class="custdiv">
                        <hr>
                        <h3>Company Information</h3>
                        <hr>
                        <table class="table table-hover table-striped">
                            <tr>
                                <td>Company Name:</td>
                                <td>{{form.companyname}}</td>
                            </tr>
                            <tr>
                                <td>Phone:</td>                         
                                <td> {{form.phone}} </td>
                            </tr>
                            <tr>
                                <td>Total Veh:</td>                         
                                <td>{{form.numberofcars}}</td>
                            </tr>
                            <tr>
                                <td>Status:</td>                            
                                <td>{{form.status}}</td>
                            </tr>
                            <tr>
                                <td>Address: </td>
                                <td>{{form.address}}</td>
                            </tr>
                            <tr>
                                <td>Unit: </td>
                                <td>{{form.unitno}}</td>
                            </tr>
                            <tr>
                                <td>City:</td>
                                <td>{{form.city}}</td>
                            </tr>
                            <tr>
                                <td>Province: </td>
                                <td>{{form.provincestate}}</td>
                            </tr>
                            <tr>
                                <td>Country: </td>
                                <td>{{form.country}}</td>
                            </tr>
                            <tr>
                                <td>Postal/Zip</td>
                                <td>{{form.postalcode}} </td>
                            </tr>   
                        </table>


    enter code here



                    </div>
                </div>
                <div class="col">
                    <div class="custdiv">
                    <hr aria-colcount="1">
                    <h3>System Information</h3>
                    <hr>
                    <table class="table table-hover table-striped">
                        <tr>
                            <td>XDS Version</td>
                            <td>{{form.xdsversion}}</td>
                        </tr>
                        <tr>
                            <td>CallBack Version</td>
                            <td>{{form.callbackversion}}</td>
                        </tr>
                        <tr>
                            <td>SMS Version</td>
                            <td>{{form.smsversion}}</td>
                        </tr>
                        <tr>
                            <td>Ngate Version</td>
                            <td>{{form.ngateversion}}</td>
                        </tr>
                        <tr>
                            <td>XCD version</td>
                            <td>{{form.xcdccversion}}</td>
                        </tr>
                        <tr>
                            <td>FleetAPI Version</td>
                            <td>{{form.fleetapiversion}}</td>
                        </tr>
                        <tr>
                            <td>IBS version</td>
                            <td>{{form.ibsversion}}</td>
                        </tr>
                        <tr>
                            <td>IBS Link</td>
                            <td>{{form.ibstestlink}}</td>
                        </tr>
                    </table>

                    </div>
                </div>
                <div class="col">
                    <div class="custdiv">
                        <hr>
                        <h3>Misc Information</h3>
                        <hr>

                        <table class="table table-hover table-striped">
                            <tr>
                                <td><strong>Info</strong></td>
                                <td>{{form.comments}}</td>
                            </tr>
                            <tr>
                                <td>Gate IPAddress</td>
                                <td>{{form.gateIP}}</td>
                            </tr>
                            <tr>
                                <td>Gate Port</td>
                                <td>{{form.gatePort}}</td>
                            </tr>
                            <tr>
                                <td>Phone System</td>
                                <td>{{form.phonesystem}}</td>
                            </tr>

                        </table>

                    </div>

                </div>

        </div>
    </div>
    <input class="btn btn-success" type="submit" name="Save"> <a class ="btn btn-warning" href="{%url 'inservice:company_list'%}">Home Changes</a>   
</form>

0 个答案:

没有答案