day25-CRM项目
一、需求分析
公司一般情况下都会做crm的客户关系管理系统,我们先整理一下crm的需求,需求如下:
二、表结构设计
2.1、表结构设计图
2.2、表结构的设计代码
说明:我们在django的crm项目的model的代码如下:
from django.db import models from django.contrib.auth.models import User # Create your models here. class Customer(models.Model): """客户信息表""" name = models.CharField(max_length=32,blank=True,null=True) qq = models.CharField(max_length=64,unique=True) qq_name = models.CharField(max_length=64,blank=True,null=True) phone = models.CharField(max_length=64,blank=True,null=True) source_choices = ((0,'转介绍'), (1,'QQ'), (2,'官网'), (3,'百度推广'), (4,'51CTO'), (5,'知乎'), (6,'市场推广'), ) source = models.SmallIntegerField(choices=source_choices) referral_from = models.CharField(verbose_name="转介绍人QQ",max_length=64,blank=True,null=True) consult_course = models.ForeignKey("Course",verbose_name="咨询课程",on_delete=models.CASCADE) content = models.TextField(verbose_name="咨询详情") tags = models.ManyToManyField("Tag",blank=True,null=True) consultant = models.ForeignKey("UserProfile",verbose_name="课程顾问",on_delete=models.CASCADE) memo = models.TextField(blank=True,null=True,verbose_name="备注") date = models.DateTimeField(auto_now_add=True,verbose_name="咨询日期") def __str__(self): return self.qq class Meta: verbose_name_plural = "客户表" class Tag(models.Model): """标签""" name = models.CharField(unique=True,max_length=32,verbose_name="标签名") def __str__(self): return self.name class Meta: verbose_name_plural = "标签" class CustomerFollowUp(models.Model): """客户跟进表""" customer = models.ForeignKey("Customer",on_delete=models.CASCADE) content = models.TextField(verbose_name="跟进内容") consultant = models.ForeignKey("UserProfile",on_delete=models.CASCADE) intention_choice = ((0,'2周内报名'), (1,'1个月内报名'), (2,'近期无报名计划'), (3,'已在其他机构报名'), (4,'已报名'), (5,'已拉黑'), ) intention = models.SmallIntegerField(choices=intention_choice,verbose_name="意向") date = models.DateTimeField(auto_now_add=True,verbose_name="跟进日期") def __str__(self): return "<%s : %s>"%(self.customer.qq,self.intention) class Meta: verbose_name_plural = "客户跟进表" class Course(models.Model): """课程表""" name = models.CharField(max_length=64,unique=True,verbose_name="课程名") price = models.PositiveSmallIntegerField(verbose_name="学费") #表示是正数,学费不能是负数 period = models.PositiveSmallIntegerField(verbose_name="周期(月)") outline = models.TextField(verbose_name="课程大纲") def __str__(self): return self.name class Meta: verbose_name_plural = "课程表" class Branch(models.Model): """校区""" name = models.CharField(max_length=128,unique=True,verbose_name="校区名") addr = models.CharField(max_length=128,verbose_name="校区地址") def __str__(self): return self.name class Meta: verbose_name_plural = "校区" class ClassList(models.Model): """班级表""" branch = models.ForeignKey("Branch",verbose_name="校区",on_delete=models.CASCADE) course = models.ForeignKey("Course",verbose_name="课程",on_delete=models.CASCADE) class_type_choice = ((0,"面授(脱产)"), (1,"面授(周末班)"), (2,"网络") ) class_type = models.SmallIntegerField(choices=class_type_choice,verbose_name="班级类型") semester = models.PositiveSmallIntegerField(verbose_name="学期") teachers = models.ManyToManyField('UserProfile',blank=True,null=True,verbose_name="讲师") start_date = models.DateField(verbose_name="开班日期") end_date = models.DateField(verbose_name="结业日期",blank=True,null=True) def __str__(self): return "<%s:%s:%s>"%(self.branch,self.course,self.semester) class Meta: unique_together = ("branch","course","semester") verbose_name_plural = "班级表" class CourseRecord(models.Model): """上课记录""" from_class = models.ForeignKey("ClassList",verbose_name="班级",on_delete=models.CASCADE) day_num = models.PositiveSmallIntegerField(verbose_name="第几节(天)") teacher = models.ForeignKey("UserProfile",on_delete=models.CASCADE) has_homework = models.BooleanField(default=True) homework_title = models.CharField(max_length=128,blank=True,null=True) homework_content = models.TextField(blank=True,null=True) outline = models.TextField(verbose_name="本节课程大纲") date = models.DateField(auto_now_add=True) def __str__(self): return "%s %s"%(self.from_class,self.day_num) class Meta: unique_together = ("from_class","day_num") class StudyRecord(models.Model): """学习记录""" student = models.ForeignKey("Enrollment",verbose_name="报名学生",on_delete=models.CASCADE) course_record = models.ForeignKey("CourseRecord",on_delete=models.CASCADE) attendance_choice = ((0,'已签到'), (1,'迟到'), (2,'缺勤'), (3,'早退'), ) attendance = models.SmallIntegerField(choices=attendance_choice,default=0,verbose_name="考勤记录") score_choices = ((100,'A+'), (90,'A'), (85,'B+'), (80,'B'), (75,'B-'), (70,'C+'), (60,'C'), (40,'C-'), (-50,'D'), (0,'N/A'), ) score = models.SmallIntegerField(choices=score_choices,verbose_name="作业成绩",default=0) memo = models.TextField(blank=True,null=True,verbose_name="批作业备注") date = models.DateField(auto_now_add=True) def __str__(self): return "%s %s %s"%(self.student,self.course_record,self.score) class Meta: unique_together = ("student","course_record") verbose_name_plural = "学习记录" class Enrollment(models.Model): """报名表""" customer = models.ForeignKey("Customer",verbose_name="报名客户",on_delete=models.CASCADE) enrolled_class = models.ForeignKey("ClassList",verbose_name="所报班级",on_delete=models.CASCADE) consultant = models.ForeignKey("UserProfile",verbose_name="课程顾问",on_delete=models.CASCADE) contract_agreed = models.BooleanField(default=False,verbose_name="学院已同意合用条款") contract_approved = models.BooleanField(default=False,verbose_name="合同已审核") date = models.DateTimeField(auto_now_add=True,verbose_name="报名时间") def __str__(self): return "%s %s"%(self.customer,self.enrolled_class) class Meta: unique_together = ("customer","enrolled_class") class Payment(models.Model): """缴费记录""" customer = models.ForeignKey("Customer",on_delete=models.CASCADE) course = models.ForeignKey("Course",verbose_name="所报课程",on_delete=models.CASCADE) amount = models.PositiveIntegerField(verbose_name="缴费金额",default=500) consultant = models.ForeignKey("UserProfile",verbose_name="课程顾问收费",on_delete=models.CASCADE) date = models.DateTimeField(auto_now_add=True) def __str__(self): return "%s %s"%(self.customer,self.amount) class UserProfile(models.Model): """账号表""" user = models.OneToOneField(User,on_delete=models.CASCADE) name = models.CharField(max_length=32) roles = models.ManyToManyField("Role",blank=True,null=True) def __str__(self): return self.name class Role(models.Model): """角色表""" name = models.CharField(max_length=32,unique=True) def __str__(self): return self.name
2.3、进入Python交互器
说明:python manage.py shell 当前Django 环境的Python 交互器,只用于Django的环境下。
D:\PycharmProjects\Taiwulink>dir 驱动器 D 中的卷是 新加卷 卷的序列号是 B8A6-53F0 D:\PycharmProjects\Taiwulink 的目录(django的一个项目) 2018/09/10 14:53 <DIR> . 2018/09/10 14:53 <DIR> .. 2018/09/10 16:53 <DIR> .idea 2018/09/10 14:53 0 db.sqlite3 2018/08/16 16:56 556 manage.py 2018/09/10 14:48 <DIR> static 2018/09/10 15:17 <DIR> Taiwulink 2018/09/10 15:55 <DIR> templates 2018/09/10 15:40 <DIR> testlink 2 个文件 556 字节 7 个目录 47,988,514,816 可用字节 D:\PycharmProjects\Taiwulink>python manage.py shell Python 3.6.6 (v3.6.6:4cf1f54eb7, Jun 27 2018, 03:37:03) [MSC v.1900 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. (InteractiveConsole) >>> from testlink import models >>> models.object....
前端模板:https://www.cnblogs.com/asker009/p/9524662.html