表结构分析:
from django.db import models # Create your models here. from django.db import models from django.contrib.auth.models import AbstractUser # 使用了django原生的user表 class UserInfo(AbstractUser): tel = models.CharField(max_length=32) # 会议室表 class Room(models.Model): """ 会议室表 """ caption = models.CharField(max_length=32) # 会议室名称 num = models.IntegerField() # 容纳人数 def __str__(self): return self.caption # 预定信息 class Book(models.Model): """ 会议室预定信息 """ user = models.ForeignKey('UserInfo', on_delete=models.CASCADE) # 预定的人 room = models.ForeignKey('Room', on_delete=models.CASCADE) # 预定的房间 date = models.DateField() # 预定会议室时间 # 这里只是定义了一个元祖而已 time_choices = ( (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'), ) time_id = models.IntegerField(choices=time_choices) class Meta: # 联合唯一不能重复,限制了不能一个时间出现2次预定 unique_together = ( ('room', 'date', 'time_id'), ) def __str__(self): return str(self.user) + "预定了" + str(self.room)