其他分享
首页 > 其他分享> > # django实例一

# django实例一

作者:互联网

django实例一

1. 设计表结构

models.py

from tkinter import CASCADE
from django.db import models

# Create your models here.
class Department(models.Model):
    ###部门表###
    title=models.CharField(verbose_name='标题',max_length=32) 

class UserInfo(models.Model):
    ###员工表###
    name=models.CharField(verbose_name='姓名',max_length=32)
    password=models.CharField(verbose_name='密码',max_length=64)
    age=models.IntegerField(verbose_name='年龄')
    account=models.DecimalField(verbose_name='用户余额',max_digits=10,decimal_places=2,default=0)
    create_time=models.DateTimeField(verbose_name='入职时间')

    #1.外键约束 生成数据列 depart_id
        #1.1 CASCADE级联删除,部门表删除,相应的员工行删除
    depart=models.ForeignKey(to='Department',to_field='id',on_delete=models.CASCADE)
        #1.2 置空
    # depart=models.ForeignKey(to='Department',to_field='id',null=True,on_delete=models.SET_NULL)

    #2.在django中做约束
    gender_choices=(
        (1,'男'),
        (2,'女'),
    )
    gender=models.SmallIntegerField(verbose_name='性别',choices=gender_choices)

2. 部门管理

体验最原始方法

2.1 部门列表

vscode html自动补全切换语言模:
ctrl+shift+p
change language mode

设计html

1.下载bootstrap和jquery
2.在html中引用css和js

<link rel='stylesheet' href="{% static 'plugins\bootstrap-3.4.1\css\bootstrap.min.css' %}">
<script src="{% static 'js\jquery-3.6.0.min.js'%}"></script>
<script src="{% static 'plugins\bootstrap-3.4.1\js\bootstrap.min.js'%}"></script>

3.到bootstrap网站找相应的素材

代码:

{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel='stylesheet' href="{% static 'plugins\bootstrap-3.4.1\css\bootstrap.min.css' %}">
    <style>
        .navbar{
            border-radius:0;
        }
    </style>
</head>
<body>
    <nav class="navbar navbar-default">
        <div class="container-fluid">
          <!-- Brand and toggle get grouped for better mobile display -->
          <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
              <span class="sr-only">Toggle navigation</span>
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>
              <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="#">学校用户管理系统</a>
          </div>
      
          <!-- Collect the nav links, forms, and other content for toggling -->
          <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
            <ul class="nav navbar-nav">
              <li ><a href="/depart/list/">部门管理 </a></li>
              <li ><a href="/depart/list/">部门管理 </a></li>
            </ul>
            
            <ul class="nav navbar-nav navbar-right">
              <li><a href="#">登录</a></li>
              <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">刘一骏 <span class="caret"></span></a>
                <ul class="dropdown-menu">
                  <li><a href="#">个人信息</a></li>
                  <li><a href="#">我的信息</a></li>
                  <li role="separator" class="divider"></li>
                  <li><a href="#">注销</a></li>
                </ul>
              </li>
            </ul>
          </div>
        </div>
    </nav>
    <div>
        <div class="container">
            <div style="margin-bottom: 10px;">
            <a href="#" class="btn btn-success">
              <span class="glyphicon glyphicon-plus-sign" aria-hidden="true"></span>
              新建部门
            </a>
            </div>
            <div class="panel panel-default">
              <!-- Default panel contents -->
              <div class="panel-heading">
                <span class="glyphicon glyphicon-th-list" aria-hidden="true"></span>
                部门列表
              </div>
        
              <!-- Table -->
              <table class="table table-bordered">
                <thead>
                  <tr>
                    <th>ID</th>
                    <th>名称</th>
                    <th>操作</th>
                  </tr>
                </thead>
                <tbody>
                  <tr>
                    <th>1</th>
                    <td>后勤部</td>
                    <td>
                        <a href="#" class="btn btn-primary btn-xs">编辑</a>
                        <a href="#" class="btn btn-danger btn-xs">删除</a>
                    </td>
                  </tr>
                  
                </tbody>
              </table>
            </div>
        </div>
    </div>
    <script src="{% static 'js\jquery-3.6.0.min.js'%}"></script>
    <script src="{% static 'plugins\bootstrap-3.4.1\js\bootstrap.min.js'%}"></script>
</body>

</html>

标签:verbose,models,max,django,实例,###,name
来源: https://www.cnblogs.com/lyjedu/p/16418716.html