python会议室系统预定_Python-S9—Day86-ORM项目实战之会议室预定相关

这是一个基于Django的web应用示例,实现了用户登录功能和房间预订的展示。用户通过POST提交用户名和密码进行身份验证,成功后重定向到首页。首页显示当前日期及可预订的房间和时间,预订信息根据用户权限展示,已预订的单元格会显示预订用户信息。
摘要由CSDN通过智能技术生成

from django.shortcuts importrender, redirect#Create your views here.

from django.contrib importauthfrom .models import *

importdatetimedeflogin(request):if request.method == "POST":

user= request.POST.get('user')

pwd= request.POST.get('pwd')

user= auth.authenticate(username=user, password=pwd)ifuser:

auth.login(request, user)#request.user

return redirect("/index/")return render(request, "login.html")defindex(request):

date=datetime.datetime.now().date()

book_date= request.GET.get("book_date", date)

time_choices=Book.time_choices

room_list=Room.objects.all()

book_list= Book.objects.filter(date=book_date)

htmls= ""

for room inroom_list:

htmls+= "

{}({})".format(room.caption, room.num)for time_choice intime_choices:

flag=Falsefor book inbook_list:if book.room.pk == room.pk and book.time_id ==time_choice[0]:

flag=Truebreak #意味着这个单元格已经被预定;

ifflag:if request.user.pk ==book.user.pk:

htmls+= "

{}".format(room.pk, time_choice[0],

book.user)else:

htmls+= "

{}".format(room.pk,

time_choice[0],

book.user)else:

htmls+= "

".format(room.pk, time_choice[0],

)

htmls+= "

"

print(htmls)return render(request, "index.html", locals())

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值