CRM需求分析
随着信息化时代带来的科技创新,CRM客户关系管理系统带来的效益在已经成为很多企业提高竞争优势的一分部,CRM客户关系管理系统将企业管理和客户关系管理集成到统一的平台,其系统功能主要体现在企业与客户之间的业务和企业内部之前部门之间的业务。因此CRM客户关系管理系统不但可以记录企业自内部信息,对于客户信息存储也是可以做到的,其中还涉及市场竞争对手的情报资料,还包括了企业进行营销、销售及支持服务所需的各种数据。
- 创建项目:
- 根据关系编写model 认证方式继承于django自带认证from django.contrib.auth.models import User
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="咨询课程")
content = models.TextField(verbose_name="咨询详情")
tags = models.ManyToManyField("Tag",blank=True,null=True)
status_choices = ((0,'已报名'),
(1,'未报名'),
)
status = models.SmallIntegerField(choices=status_choices,default=1)
consultant = models.ForeignKey("UserProfile")
memo = models.TextField(blank=True,null=True)
date = models.DateTimeField(auto_now_add=True) def __str__(self):
return self.qq class Meta:
verbose_name ="客户表"
verbose_name_plural ="客户表" class Tag(models.Model):
name = models.CharField(unique=True,max_length=32) def __str__(self):
return self.name class Meta:
verbose_name = "标签"
verbose_name_plural = "标签" class CustomerFollowUp(models.Model):
'''客户跟进表'''
customer = models.ForeignKey("Customer")
content = models.TextField(verbose_name="跟进内容")
consultant = models.ForeignKey("UserProfile") intention_choices = ((0,'2周内报名'),
(1,'1个月内报名'),
(2,'近期无报名计划'),
(3,'已在其它机构报名'),
(4,'已报名'),
(5,'已拉黑'),
)
intention = models.SmallIntegerField(choices=intention_choices)
date = models.DateTimeField(auto_now_add=True) def __str__(self):
return "<%s : %s>" %(self.customer.qq,self.intention) class Meta:
verbose_name = "客户跟进记录"
verbose_name_plural = "客户跟进记录" class Course(models.Model):
'''课程表'''
name = models.CharField(max_length=64,unique=True)
price = models.PositiveSmallIntegerField()
period = models.PositiveSmallIntegerField(verbose_name="周期(月)")
outline = models.TextField() def __str__(self):
return self.name class Meta:
verbose_name = "课程表"
verbose_name_plural = "课程表" class Branch(models.Model):
'''校区'''
name = models.CharField(max_length=128,unique=True)
addr = models.CharField(max_length=128)
def __str__(self):
return self.name class Meta:
verbose_name = "校区"
verbose_name_plural = "校区" class ClassList(models.Model):
'''班级表'''
branch = models.ForeignKey("Branch",verbose_name="校区")
course = models.ForeignKey("Course")
class_type_choices = ((0,'面授(脱产)'),
(1,'面授(周末)'),
(2,'网络班')
)
class_type = models.SmallIntegerField(choices=class_type_choices,verbose_name="班级类型")
semester = models.PositiveSmallIntegerField(verbose_name="学期")
teachers = models.ManyToManyField("UserProfile")
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 = "班级"
verbose_name = "班级" class CourseRecord(models.Model):
'''上课记录'''
from_class = models.ForeignKey("ClassList",verbose_name="班级")
day_num = models.PositiveSmallIntegerField(verbose_name="第几节(天)")
teacher = models.ForeignKey("UserProfile")
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")
verbose_name_plural = "上课记录" class StudyRecord(models.Model):
'''学习记录'''
student = models.ForeignKey("Enrollment")
course_record = models.ForeignKey("CourseRecord")
attendance_choices = ((0,'已签到'),
(1,'迟到'),
(2,'缺勤'),
(3,'早退'),
)
attendance = models.SmallIntegerField(choices=attendance_choices,default=0)
score_choices = ((100,"A+"),
(90,"A"),
(85,"B+"),
(80,"B"),
(75,"B-"),
(70,"C+"),
(60,"C"),
(40,"C-"),
(-50,"D"),
(-100,"COPY"),
(0,"N/A"),
)
score = models.SmallIntegerField(choices=score_choices,default=0)
memo = models.TextField(blank=True,null=True)
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")
enrolled_class = models.ForeignKey("ClassList",verbose_name="所报班级")
consultant = models.ForeignKey("UserProfile",verbose_name="课程顾问")
contract_agreed = models.BooleanField(default=False,verbose_name="学员已同意合同条款")
contract_approved = models.BooleanField(default=False,verbose_name="合同已审核")
date = models.DateTimeField(auto_now_add=True) def __str__(self):
return "%s %s" %(self.customer,self.enrolled_class) class Meta:
unique_together = ("customer","enrolled_class")
verbose_name_plural = "报名表" class Payment(models.Model):
'''缴费记录'''
customer = models.ForeignKey("Customer")
course = models.ForeignKey("Course",verbose_name="所报课程")
amount = models.PositiveIntegerField(verbose_name="数额",default=500)
consultant = models.ForeignKey("UserProfile")
date = models.DateTimeField(auto_now_add=True) def __str__(self):
return "%s %s" %(self.customer,self.amount) class Meta:
verbose_name_plural = "缴费记录" class UserProfile(models.Model):
'''账号表'''
user = models.OneToOneField(User)
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)
menus = models.ManyToManyField("Menu",blank=True) def __str__(self):
return self.name
class Meta:
verbose_name_plural = "角色" class Menu(models.Model):
'''菜单'''
name = models.CharField(max_length=32)
url_name = models.CharField(max_length=64) def __str__(self):
return self.name
models.py
- 注册数据表
from django.contrib import admin from crm import models admin.site.register(models.Customer) admin.site.register(models.CustomerFollowUp) admin.site.register(models.Enrollment) admin.site.register(models.Course) admin.site.register(models.ClassList) admin.site.register(models.CourseRecord) admin.site.register(models.Branch) admin.site.register(models.Role) admin.site.register(models.Payment) admin.site.register(models.StudyRecord) admin.site.register(models.Tag) admin.site.register(models.UserProfile) admin.site.register(models.Menu)
Python manage.py makemigrations python manage.py migrate
C:\Users\MrTong\Desktop\django\EasyCRM>Python manage.py makemigrations
System check identified some issues:
WARNINGS:
crm.Customer.tags: (fields.W340) null has no effect on ManyToManyField.
crm.UserProfile.roles: (fields.W340) null has no effect on ManyToManyField.
Migrations for 'crm':
crm\migrations\0001_initial.py
- Create model Branch
- Create model ClassList
- Create model Course
- Create model CourseRecord
- Create model Customer
- Create model CustomerFollowUp
- Create model Enrollment
- Create model Menu
- Create model Payment
- Create model Role
- Create model StudyRecord
- Create model Tag
- Create model UserProfile
- Add field consultant to payment
- Add field course to payment
- Add field customer to payment
- Add field consultant to enrollment
- Add field customer to enrollment
- Add field enrolled_class to enrollment
- Add field consultant to customerfollowup
- Add field customer to customerfollowup
- Add field consultant to customer
- Add field tags to customer
- Add field teacher to courserecord
- Add field course to classlist
- Add field teachers to classlist
- Alter unique_together for studyrecord (1 constraint(s))
- Alter unique_together for enrollment (1 constraint(s))
- Alter unique_together for courserecord (1 constraint(s))
- Alter unique_together for classlist (1 constraint(s))
C:\Users\MrTong\Desktop\django\EasyCRM>Python manage.py migrate
System check identified some issues:
WARNINGS:
crm.Customer.tags: (fields.W340) null has no effect on ManyToManyField.
crm.UserProfile.roles: (fields.W340) null has no effect on ManyToManyField.
Operations to perform:
Apply all migrations: admin, auth, contenttypes, crm, sessions
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK
Applying auth.0008_alter_user_username_max_length... OK
Applying crm.0001_initial... OK
Applying sessions.0001_initial... OK
生成数据表
-
创建管理用户 (密码不能纯数字)
Python manage.py createsuperuser
C:\Users\MrTong\Desktop\django\EasyCRM>python manage.py createsuperuser
System check identified some issues:
WARNINGS:
crm.Customer.tags: (fields.W340) null has no effect on ManyToManyField.
crm.UserProfile.roles: (fields.W340) null has no effect on ManyToManyField.
Username (leave blank to use 'mrtong'):
Email address: abc@qq.com
Password:
Password (again):
Superuser created successfully.
创建超级用户
- OK 先来登陆admin吧
- 接下来创建几条数据吧!
class CustomerAdmin(admin.ModelAdmin):
list_display = ('id','qq','source','consultant','content','status','date')
list_filter = ('source','consultant','date')
search_fields = ('qq','name')
raw_id_fields = ('consult_course',)
filter_horizontal = ('tags',)
list_editable = ('status',)
class UserProfileAdmin(admin.ModelAdmin):
list_display = ('user','name')
admin.site.register(models.Customer,CustomerAdmin)
admin.site.register(models.UserProfile,UserProfileAdmin)
admin.py
效果显而易见