ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
[TOC=1,5] >[success] # 创建表思路 >先列出需求表,在填写表的字段例如: ~~~ class UserProfile(models.Model): """用户信息表""" pass class Role(models.Model): """角色表""" pass class CustomerInfo(models.Model): """客户信息表""" pass class CustomerFollowUp(models.Model): """客户跟踪表""" pass class Course(models.Model): """课程表""" pass class ClassList(models.Model): """班级列表""" pass class CourseRecord(models.Model): """上课记录""" pass class Students(models.Model): """学生表""" pass class StudyRecord(models.Model): """上课记录""" pass class Branch(models.Model): """校区""" pass ~~~ >[danger] ##### 后续表 >权限 >问卷调查 >知识管理 >合同 * * * * * <br> >[success] # 表字段设计 <br> * * * * * >[danger] ##### 用户登录-UserProfile >**字段介绍** >user ----》 和django自带的User 字段进行一对一关联 >name ----》 用户姓名 >role -----》 权限,用户和权限进行多对多,一个用户有多个权限,多个权限可以对一个用户 ~~~ class UserProfile(models.Model): """用户信息表""" user = models.OneToOneField(User) name = models.CharField(max_length=64,verbose_name="姓名") role = models.ManyToManyField('Role',blank=True,null=True) def __str__(self): return self.name ~~~ <br> * * * * * >[danger] ##### 权限角色表-Role >**字段介绍** >name ----》 权限名称 ~~~ class Role(models.Model): """角色表""" name =models.CharField(max_length=64,unique=True) menus = models.ManyToManyField('Menus',blank=True) def __str__(self): return self.name ~~~ <br> * * * * * >[danger] ##### 客户信息表-CustomerInfo >**字段介绍** >name -----》 客户名字 contact_type_choice ----》 ((0,'qq'),(1,'微信'),(2,'手机号')) 联系方式 concat_type -----》联系方式默认0,和上面打的字段是choice关系 consult_courses ----》咨询内容和课程表多对多,可以咨询多个课程,多个课程可以被咨询 consult_content ----》咨询内容 source_choices -----》 ((0,"qq群"), (1,'51TOC'), (2,"介绍人") )获取途径 source -----》获取途径默认0,和上面打的字段是choice关系 referral_from ---》"转介绍" 自关联一对多,介绍人 status_choices -----》 ((0,'未报名'),(1,"已报名"),(2,'已退学')) status -----》学员状态默认0,和上面打的字段是choice关系 date ----》创建时间 consultant----》课程顾问和用户一对多,多个用户都可以是课程顾问 ~~~ class CustomerInfo(models.Model): """客户信息表""" name = models.CharField(max_length=64,default=None) contact_type_choice = ((0,'qq'),(1,'微信'),(2,'手机号')) concat_type = models.SmallIntegerField(choices=contact_type_choice,default=0) consult_courses = models.ManyToManyField('Course',verbose_name='咨询课程') consult_content = models.TextField(verbose_name='咨询内容') source_choices = ((0,"qq群"), (1,'51TOC'), (2,"介绍人") ) source = models.SmallIntegerField(choices=source_choices) referral_from = models.ForeignKey('self',blank=True,null=True,verbose_name="转介绍") status_choices = ((0,'未报名'),(1,"已报名"),(2,'已退学')) status = models.SmallIntegerField(choices=status_choices) date = models.DateField(auto_now_add=True) consultant = models.ForeignKey("UserProfile",verbose_name='课程顾问') ~~~ <br> * * * * * >[danger] ##### 客户跟踪表-CustomerFollowUp >**字段介绍** >customer ----》 和customerInfo用户信息表一对多 >content ----》 跟踪内容记录 >user ----》跟进人和userprofile 用户表一对多 >status_choices -----》报名状态((0,"近期无报名"), (1, "一个月报名"), (2, "2周内报名"),(3, "已报名"),) >status -----》和上面字段关联 >date ------》创建时间 ~~~ class CustomerFollowUp(models.Model): """客户跟踪表""" customer = models.ForeignKey('CustomerInfo',verbose_name="用户名字") content = models.TextField(verbose_name="跟踪内容") user = models.ForeignKey('UserProfile',verbose_name="跟进人") status_choices = ((0,"近期无报名"), (1, "一个月报名"), (2, "2周内报名"), (3, "已报名"), ) status = models.SmallIntegerField(choices=status_choices,verbose_name='学生报名') date = models.DateField(auto_now_add=True,verbose_name="创建时间") def __str__(self): return self.customer ~~~ <br> * * * * * >[danger] ##### 课程表-Course >**字段介绍** >name -----》'课程名字' unique=True唯一 price ----》"价格" period-----》课程周期(月)' outline -----》"大纲" ~~~ class Course(models.Model): """课程表""" name = models.CharField(verbose_name='课程名字',max_length=64,unique=True) price = models.PositiveIntegerField(verbose_name="价格") period = models.SmallIntegerField(verbose_name='课程周期(月)',default=5) outline = models.TextField(verbose_name="大纲") def __str__(self): return self.name ~~~ <br> * * * * * >[danger] ##### 班级列表-ClassList >**字段介绍** >course ----》'Course'一对多 semester----》"学期" teachers -----》老师 'UserProfile',多对多,一个班级多个老师 start_date --------》('开班日期') graduate_date -------》'毕业日期' branch --------》和校区一对多 Branch 表 ~~~ class ClassList(models.Model): """班级列表""" branch = models.ForeignKey('Branch',verbose_name="校区") course = models.ForeignKey('Course') semester = models.SmallIntegerField(verbose_name="学期") teachers = models.ManyToManyField('UserProfile',verbose_name="老师") start_date = models.DateField('开班日期') graduate_date = models.DateField('毕业日期',blank=True,null=True) def __str__(self): return "%s(%s)期"%(self.course.name,self.semester) class Meta: unique_together = ('branch','course','semester') verbose_name_plural =verbose_name = "班级" ~~~ <br> * * * * * >[danger] ##### 上课记录-CourseRecord >**字段介绍** > class_grade---->上课班级 和ClassList表一对多 day_num ----》"课程节次" teacher ----》老师表和UserProfile一对多 title -------》本节主题" content -----》'本节内容' has_homework ------》'本节有作业' homework --------》"作业需求", date = models.DateTimeField(auto_now_add=True) ~~~ class CourseRecord(models.Model): """上课记录""" class_grade = models.ForeignKey('ClassList',verbose_name="上课班级") day_num = models.SmallIntegerField(verbose_name="课程节次") teacher = models.ForeignKey('UserProfile') title = models.CharField("本节主题",max_length=64) content = models.TextField('本节内容') has_homework = models.BooleanField('本节有作业',default=True) homework = models.TextField("作业需求",blank=True,null=True) date = models.DateTimeField(auto_now_add=True) def __str__(self): return "%第(%s)节"%(self.class_grade,self.day_num) class Meta: unique_together = ("class_grade","day_num") verbose_name = '上课记录' verbose_name_plural = verbose_name ~~~ <br> * * * * * >[danger] ##### 学习记录-StudyRecord >**字段介绍** >curse_record ----》 和上课记录一对多('CourseRecord') student = ---->学生和('Student')一对多 score_choices ----》 ((100,"A"),(59,"不及格")) score----》学生成绩和上面字段关联 show_choices ----》 ((0,"缺勤"),(1,"签到"),(2,"迟到/早退")) show_status ---》学生上课记录和上面字段关联 note----》"备注" ~~~ class StudyRecord(models.Model): """学习记录""" course_record = models.ForeignKey('CourseRecord') student = models.ForeignKey('Student') score_choices = ((100,"A"),(59,"不及格")) score = models.SmallIntegerField(choices=score_choices) show_choices = ((0,"缺勤"),(1,"签到"),(2,"迟到/早退")) show_status = models.SmallIntegerField(choices=show_choices,default=1) note = models.TextField("备注",null=True,blank=True) def __str__(self): return "%s %s %s"%(self.course_record,self.student,self.score) class Meta: verbose_name_plural =verbose_name = "学习记录" ~~~ <br> * * * * * >[danger] ##### 学员表-Student >**字段介绍** >customer ----》用户信息'CustomerInfo' class_grades ----》'班级'和 classlist 多对多 ~~~ class Student(models.Model): """学员表""" customer = models.ForeignKey('CustomerInfo') class_grades = models.ManyToManyField('ClassList',verbose_name='班级') class Meta: verbose_name_plural =verbose_name = "学员" ~~~ <br> * * * * * >[danger] ##### 校区-Branch >**字段介绍** >name ----》名字 addr ---》地址 ~~~ class Branch(models.Model): """校区""" name = models.CharField(max_length=64,unique=True) addr = models.CharField(max_length=256,verbose_name="地址",null=True,blank=True) class Meta: verbose_name_plural="校区" ~~~ * * * * * <br> >**字段介绍** >name ----》 addr ---》地址 ~~~ class Menus(models.Model): """动态菜单""" name = models.CharField(max_length=64) url_name = models.CharField(max_length=64) url_type_chooice = ((0,'absoulte'),(1,'dynamic')) url_type = models.SmallIntegerField(choices=url_type_chooice,default=0) def __str__(self): return self.name class Meta: unique_together = ('name','url_name') ~~~ >[success] # 菜单表分析 >可以自定义网址,也可以用django urlname的属性来做相对的地址 **自定义地址**: ![](https://box.kancloud.cn/373162412c5ae36d942eac20535facf5_513x165.png) **固定地址** ![](https://box.kancloud.cn/91aa2c5844c16708323fb6a49f23e2db_557x174.png) ![](https://box.kancloud.cn/2789e95f171783c64f3066cacb143e21_598x132.png)