Hi,同学们好呀,被评为全网最细的丹成学长ヾ(•ω•`)o,今天带大家复盘一个学长帮往届同学做的一个毕业作品
基于Django的会议室预定系统
计算机毕设选题大全及项目分享:
https://blog.csdn.net/WEB_DC/article/details/125563252
业务流程:
from django.db import models
from django.contrib.auth.models import AbstractUser
# Create your models here.
class UserInfo(AbstractUser):
tel = models.CharField(max_length=32,verbose_name="电话")
avatar = models.FileField(upload_to="avatars/", default="avatars/timg.jpg", verbose_name="头像")
class Room(models.Model):
"""会议室表"""
caption = models.CharField(max_length=32,verbose_name="会议室名称")
num = models.IntegerField(verbose_name="容纳人数") # 容纳人数
def __str__(self):
return self.caption
class Meta:
verbose_name = "会议室信息"
verbose_name_plural = verbose_name
class Book(models.Model):
"""会议室预订"""
user = models.ForeignKey(to="UserInfo",on_delete=models.CASCADE)
room = models.ForeignKey(to="Room",on_delete=models.CASCADE)
date = models.DateField()
time_choice = (
(1, "8:00"),
(2, "9:00"),
(3, "10:00"),
(4, "11:00"),
(5, "12:00"),
(6, "13:00"),
(7, "14:00"),
(8, "15:00"),
(9, "16:00"),
(10, "17:00"),
(11, "18:00"),
(12, "19:00"),
(13, "20:00"),
(14, "21:00"),
(15, "22:00"),
(16, "23:00"),
)
time_id = models.IntegerField(choices=time_choice)
def __str__(self):
return str(self.user)+"预定了"+str(self.room)
class Meta:
verbose_name = "预定信息"
verbose_name_plural = verbose_name
unique_together = (
("room","date","time_id"), # 这三个字段联合唯一,防止重复预订
)
Django允许你通过修改setting.py文件中的 AUTH_USER_MODEL 设置覆盖默认的User模型,其值引用一个自定义的模型。
AUTH_USER_MODEL = "app01.UserInfo"
上面的值表示Django应用的名称(必须位于INSTALLLED_APPS中)和你想使用的User模型的名称。
注意:在创建任何迁移或者第一次运行 manager.py migrate 前设置 AUTH_USER_MODEL。
设置AUTH_USER_MODEL数据库结构有很大的影响。改变了一些会使用到的表格,并且会影响到一些外键和多对多关系的构造。在你有表格被创建后更改此设置是不被 makemigrations 支持的,并且会导致你需要手动修改数据库结构,从旧用户表中导出数据,可能重新应用一些迁移。
urls.py:
from django.conf.urls import url
from django.contrib import admin
from django.views.static import serve
from django.conf import settings
from app01 import views
urlpatterns = [
url(r'^admin/', admin.site.urls),
# 用户登录
url(r'^login/',views.acc_login),
# 展示预订信息
url(r'^index/',views.index),
# 极验滑动验证码 获取验证码的url
url(r'^pc-geetest/register', views.get_geetest),
# media相关的路由设置
url(r'^media/(?P<path>.*)$', serve, {"document_root": settings.MEDIA_ROOT}),
# 处理预订请求
url(r'^book/',views.book),
# 首页
url(r'^home/',views.home),
# 注销
url(r'^logout/',views.acc_logout),
# 用户注册
url(r'^reg/',views.reg),
# 临时测试
url(r'^test/',views.test),
# 修改密码
url(r'^change_password/',views.change_password),
]
login.html(使用了滑动验证)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>用户登录</title>
<link rel="stylesheet" href="/static/bootstrap/css/bootstrap.min.css">
<!-- 引入封装了failback的接口--initGeetest -->
<script src="http://static.geetest.com/static/tools/gt.js"></script>
</head>
<body>
<h3 class="text-center" style="color: orangered">欢迎登录会议室预订系统</h3>
<br>
<div class="container">
<div class="row">
<form class="form-horizontal col-md-6 col-md-offset-4" autocomplete="off">
{% csrf_token %}
<div class="form-group">
<label for="username" class="col-lg-2 control-label">用户名</label>
<div class="col-sm-6">
<input type="text" class="form-control" id="username" name="username" placeholder="用户名">
</div>
</div>
<div class="form-group">
<label for="pwd" class="col-lg-2 control-label">密码</label>
<div class="col-sm-6">
<input type="password" class="form-control" id="pwd" name="pwd" placeholder="密码">
</div>
</div>
<div class="form-group">
<!-- 放置极验的滑动验证码 -->
<div id="popup-captcha"></div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="button" id="login_btn" class="btn btn-info">登录</button>
<span class="login-error has-error text-danger"></span>
</div>
</div>
</form>
</div>
</div>
<script src="/static/js/jquery-3.3.1.min.js"></script>
<script src="/static/bootstrap/js/bootstrap.min.js"></script>
<script>
var handlerPopup = function (captchaObj) {
// 成功的回调
captchaObj.onSuccess(function () {
var validate = captchaObj.getValidate();
// 1. 取到用户填写的用户名和密码 -> 取input框的值
var username = $("#username").val();
var password = $("#pwd").val();
$.ajax({
url: "/login/", // 进行二次验证
type: "post",
dataType: "json",
data: {
username: username,
pwd: password,
csrfmiddlewaretoken: $("[name='csrfmiddlewaretoken']").val(),
geetest_challenge: validate.geetest_challenge,
geetest_validate: validate.geetest_validate,
geetest_seccode: validate.geetest_seccode
},
success: function (data) {
console.log(data);
if (data.status) {
// 有错误,在页面上提示
$(".login-error").text(data.msg);
} else {
// 登陆成功
location.href = data.msg;
}
}
});
});
$("#login_btn").click(function () {
captchaObj.show();
});
// 将验证码加到id为captcha的元素里
captchaObj.appendTo("#popup-captcha");
// 更多接口参考:http://www.geetest.com/install/sections/idx-client-sdk.html
};
//当再次点击input输入框时,错误提示要消失
$("#username,#pwd").focus(function () {
$(".login-error").text("");
})
// 验证开始需要向网站主后台获取id,challenge,success(是否启用failback)
$.ajax({
url: "/pc-geetest/register?t=" + (new Date()).getTime(), // 加随机数防止缓存
type: "get",
dataType: "json",
success: function (data) {
// 使用initGeetest接口
// 参数1:配置参数
// 参数2:回调,回调的第一个参数验证码对象,之后可以使用它做appendTo之类的事件
initGeetest({
gt: data.gt,
challenge: data.challenge,
product: "popup", // 产品形式,包括:float,embed,popup。注意只对PC版验证码有效
offline: !data.success // 表示用户后台检测极验服务器是否宕机,一般不需要关注
// 更多配置参数请参见:http://www.geetest.com/install/sections/idx-client-sdk.html#config
}, handlerPopup);
}
})
</script>
</body>
</html>
from django.contrib import admin
from app01 import models
from django.contrib.auth.admin import UserAdmin
from django.utils.translation import gettext_lazy
# Register your models here.
# 配置会议室信息表
class RoomConfig(admin.ModelAdmin):
list_display = ('caption','num')
list_filter=('num',)
search_fields = ('caption','num')
# 配置预订信息表
class BookConfig(admin.ModelAdmin):
list_display = ('user','room','date','time_id')
list_filter = ('user','room','date','time_id')
search_fields = ('user','room','date','time_id')
# 配置用户管理表
class UserProfileAdmin(UserAdmin):
list_display = ('username','last_login','is_superuser','is_staff','is_active','date_joined')
list_filter = ('last_login', 'is_staff', 'date_joined', 'is_active')
search_fields = ('username',)
fieldsets = (
(None,{'fields':('username','password','first_name','last_name','email')}),
(gettext_lazy('用户信息'),{'fields':('username','email','tel','avatar')}),
(gettext_lazy('用户权限'), {'fields': ('is_superuser','is_staff','is_active',
'groups', 'user_permissions')}),
(gettext_lazy('Important dates'), {'fields': ('last_login', 'date_joined')}),
)
admin.site.register(models.Room,RoomConfig)
admin.site.register(models.UserInfo,UserProfileAdmin)
admin.site.register(models.Book,BookConfig)
计算机毕设选题大全及项目分享:
https://blog.csdn.net/WEB_DC/article/details/125563252