斯巴达系统(一)
开发工具
- pycharm
- python
- django
- mysql
- jquery
- bootstrap
- linux
- nginx
表单设计:
1. # app01/model.py 2 __author__ = 'derek' 3 4 from django.db import models 5 from django.contrib.auth.models import User 6 7 8 class Role(models.Model): 9 '''角色表''' 10 name = models.CharField(max_length=64,unique=True) #不能重 11 12 13 class UserProfile(models.Model): 14 '''用户信息表''' 15 #关联django自带的User,可以自己扩展字段 16 user = models.ForeignKey(User,on_delete=models.CASCADE) 17 name = models.CharField('姓名',max_length=64) 18 #一个用户可以有多个角色,一个角色可以对应多个用户 19 role = models.ManyToManyField(Role,blank=True,null=True) 20 21 def __str__(self): 22 return self.name 23 24 25 class CustomerInfo(models.Model): 26 '''客户信息表''' 27 name = models.CharField('姓名',max_length=64,default=None) 28 contact_type_choices = ((0,'qq'),(1,'微信'),(2,'手机')) 29 contact_type = models.SmallIntegerField(choices=contact_type_choices,default=0) 30 contact = models.CharField('联系方式',max_length=64,unique=True) 31 source_choices = ((0,'qq群'),(1,'51CTO'),(2,'百度推广'),(3,'知乎'),(4,'转介绍'),(5,'其它'),) 32 source = models.SmallIntegerField('客户来源',choices=source_choices) 33 #关联自己,如果是转介绍(介绍人已经是学员,然后介绍别人过来学习),需要填写转介绍人的信息,不是转介绍,这里就可以为空 34 referral_from = models.ForeignKey('self',blank=True,null=True,verbose_name='转介绍',on_delete=models.CASCADE) 35 #可以咨询多个课程 36 consult_courses = models.ManyToManyField('Course',verbose_name='咨询课程') 37 consult_content = models.TextField('咨询内容',) 38 status_choices = ((0,'未报名'),(1,'已报名'),(2,'已经退学')) 39 status = models.SmallIntegerField('客户状态',choices=status_choices) 40 consultant = models.ForeignKey('UserProfile',verbose_name='课程顾问',on_delete=models.CASCADE) 41 date = models.DateField('创建的时间',auto_now_add=True) 42 43 44 class Student(models.Model): 45 '''学员表''' 46 customer = models.ForeignKey('CustomerInfo',verbose_name='客户',on_delete=models.CASCADE) 47 class_grades = models.ManyToManyField('ClassList',verbose_name='班级') 48 49 def __str__(self): 50 return self.customer 51 52 53 class CustomerFollowUp(models.Model): 54 '''客户跟踪记录表''' 55 customer = models.ForeignKey('CustomerInfo',on_delete=models.CASCADE) 56 content = models.TextField('跟踪内容',) 57 user = models.ForeignKey('UserProfile',verbose_name='跟进人',on_delete=models.CASCADE) 58 status_choices = ((0,'近期无报名计划'),(1,'一个月内报名'),(2,'半个月报名'),(3,'已报名'),) 59 status = models.SmallIntegerField('客户状态',choices=status_choices) 60 date = models.DateField('创建的时间', auto_now_add=True) 61 62 63 class Course(models.Model): 64 '''课程表''' 65 name = models.CharField('课程名称',max_length=64,unique=True) 66 #价格必须为整数 67 price = models.PositiveSmallIntegerField('价格',) 68 period = models.PositiveSmallIntegerField('课程周期(月)',default=5) 69 outline = models.TextField('大纲',) 70 71 def __str__(self): 72 return self.name 73 74 75 class ClassList(models.Model): 76 '''班级列表''' 77 branch = models.ForeignKey('Branch',verbose_name='校区',on_delete=models.CASCADE) 78 #一个班级只能有一个课程,一个课程可以有多个班级 79 course = models.ForeignKey('Course',verbose_name='课程',on_delete=models.CASCADE) 80 class_type_choices = ((0,'脱产'),(1,'周末'),(2,'网络班')) 81 class_type = models.SmallIntegerField('班级类型',choices=class_type_choices,default=0) 82 semester = models.SmallIntegerField('学期',) 83 teachers = models.ManyToManyField('UserProfile',verbose_name='讲师') 84 start_date = models.DateField('开班日期',) 85 #毕业日期因为不固定,所以可以为空 86 graduate_date = models.DateField('毕业日期',blank=True,null=True) 87 88 def __str__(self): 89 #班级名是课程名+第几期拼接起来的 90 return "%s(%s)期"%(self.course.name,self.semester) 91 92 class Meta: 93 #联合唯一,班级不能重复 94 unique_together = ('branch','class_type','course','semester') 95 96 97 class CourseRecord(models.Model): 98 '''上课记录''' 99 class_grade = models.ForeignKey('ClassList',verbose_name='上课班级',on_delete=models.CASCADE) 100 day_num = models.PositiveSmallIntegerField('课程节次',) 101 teacher = models.ForeignKey('UserProfile',verbose_name='讲师',on_delete=models.CASCADE) 102 title = models.CharField('本节主题',max_length=64) 103 content = models.TextField('本节内容',) 104 has_homework = models.BooleanField('本节有作业',default=True) 105 homework = models.TextField('作业需求',blank=True,null=True) 106 date = models.DateField('创建的时间', auto_now_add=True) 107 108 def __str__(self): 109 #上课班级+课程节次 110 return "%s第(%s)节"%(self.class_grade,self.day_num) 111 112 class Meta: 113 unique_together = ('class_grade','day_num') 114 115 116 class StudyRecord(models.Model): 117 '''学习记录表''' 118 #一节课对应多个学生 119 course_record = models.ForeignKey('CourseRecord',verbose_name='课程') 120 #一个学生有多个上课记录 121 student = models.ForeignKey('Student',verbose_name='学生',on_delete=models.CASCADE) 122 score_choices = ((100,'A+'), 123 (90,'A'), 124 (85,'B+'), 125 (80,'B'), 126 (75,'B-'), 127 (70,'C+'), 128 (60,'C'), 129 (40,'C-'), 130 (-50,'D'), 131 (0,'N/A'), #not avaliable 132 (-100,'COPY'), #抄作业 133 ) 134 score = models.SmallIntegerField('得分',choices=score_choices,default= 0) 135 show_choices = ((0,'缺勤'), 136 (1,'已签到'), 137 (2,'迟到'), 138 (3,'早退'), 139 ) 140 show_status = models.SmallIntegerField('出勤',choices=show_choices,default=1) 141 note = models.TextField('成绩备注',blank=True,null=True) 142 date = models.DateField('创建的时间', auto_now_add=True) 143 144 def __str__(self): 145 return "%s %s %s"%(self.course_record,self.student,self.score) 146 147 148 class Branch(models.Model): 149 '''校区分支''' 150 name = models.CharField('校区名',max_length=64,unique=True) 151 addr = models.CharField('地址',max_length=128,blank=True,null=True) 152 153 def __str__(self): 154 return self.name
注册models
1 #app01/admin.py 2 3 from django.contrib import admin 4 from crm import models 5 6 admin.site.register(models.Role) 7 admin.site.register(models.CustomerInfo) 8 admin.site.register(models.Student) 9 admin.site.register(models.CustomerFollowUp) 10 admin.site.register(models.Course) 11 admin.site.register(models.ClassList) 12 admin.site.register(models.CourseRecord) 13 admin.site.register(models.StudyRecord) 14 admin.site.register(models.Branch)
数据库配置:
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'perfectcrm', #数据库名字 'USER': 'root', #账号 'PASSWORD': '123456', #密码 'HOST': '127.0.0.1', #IP 'PORT': '3306', #端口 } }
__init__.py配置pymysql
import pymysql pymysql.install_as_MySQLdb()
设置中文:
LANGUAGE_CODE = 'zh-hans' TIME_ZONE = 'Asia/Shanghai' USE_I18N = True USE_L10N = True USE_TZ = False