<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                >[success] # 基礎案例 ~~~ 1.創建表時會默認創建自增列id字段 2.創建兩個表的字段關系用ForeignKey 3.ForeignKey的變量名實際是關聯表的對象,實際字段是變量名_id ~~~ >[danger] ##### model.py ~~~ from django.db import models # Create your models here. class Business(models.Model): caption = models.CharField(max_length=32) class Host(models.Model): nid = models.AutoField(primary_key=True) hostname = models.CharField(max_length=32) bussiness = models.ForeignKey(Business) ~~~ >[danger] ##### views.py ~~~ from django.shortcuts import render,redirect # Create your views here. from . import models def index(request): if request.method == "GET": hostobj = models.Host.objects.all() busobj = models.Business.objects.all() return render(request,'index.html',{'hostobj':hostobj,"busobj":busobj}) if request.method == "POST": h = request.POST.get('hostname',None) b = request.POST.get('b_name',None) models.Host.objects.create(hostname=h,bussiness_id=b) return redirect('/index/') ~~~ >[danger] ##### templates ~~~ <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> .hid{ display: none; } .back{ position: fixed; left: 0; right: 0; bottom: 0; top: 0; background:black; opacity:0.3; z-index: 100; } .add_modal{ position: fixed; height: 400px; width: 500px; top: 200px; left: 500px; background:white; z-index: 101; } </style> </head> <body> <input type="button" id="addmodel" value="添加"> <div class="hid back"> <div class="add_modal"> <form method="post"> {% csrf_token %} <input type="text" name="hostname"> <br> <select name="b_name"> {% for i in busobj %} <option value="{{i.id }}">{{ i.caption }}</option> {% endfor %} </select> <input type="submit"> </form> </div> </div> <ul> {% for i in hostobj %} <li>{{ forloop.counter }}{{ i.hostname }}-{{ i.bussiness.caption }}</li> {% endfor %} </ul> </body> <script src="/static/jquery-1.12.4.js"></script> <script> $(function () { Bindclik(); }); function Bindclik() { $('#addmodel').click( function () { $('.back').removeClass("hid") } ) } </script> </html> ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看