Django CRM客户关系管理系统

Posted Bingo

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Django CRM客户关系管理系统相关的知识,希望对你有一定的参考价值。

CRM需求分析

    随着信息化时代带来的科技创新,CRM客户关系管理系统带来的效益在已经成为很多企业提高竞争优势的一分部,CRM客户关系管理系统将企业管理和客户关系管理集成到统一的平台,其系统功能主要体现在企业与客户之间的业务和企业内部之前部门之间的业务。因此CRM客户关系管理系统不但可以记录企业自内部信息,对于客户信息存储也是可以做到的,其中还涉及市场竞争对手的情报资料,还包括了企业进行营销、销售及支持服务所需的各种数据。

功能实现
  (1)建议统一的信息编码系统;
  (2)设计能够良好反映事物特性的数据模型;
  (3)划分数据库管理,在分布式数据库管理系统和网络平台基础上,涉及全局共享及局部共享数据库,以支持分布式数据处理,实现各分系统之间及其内部各功能模块之间的信息集成。
  (4)提供强大的数据库管理系统,并在此基础上增加拿过来的完善的客户销售数据库、客户市场数据库、客户支持与服务数据库、企业综合信息数据库等。
  CRM客户关系管理系统的管理理念始终是以客户为中心的,不同的管理系统有着自己不同的数据处理方式,因此企业在构建自己的客户关系管理数据库时需要注意系统的特性和其他企业管理软件的协调。
  对于中小型企业在客户关系管理系统上的应用,可有助于企业对客户信息管理混乱状态的改善,加强了企业和客户之间的联系,因此下面是中小企业在面对客户关系管理系统时所需的需求:
   (1)因为是小型企业,系统将只设系统管理员,管理员拥有对企业全部系统资料的操作权限。
   (2)客户管理模块,基本资料的添加、修改、删除和查询功能;与客户相关的联系人资料的添加、修改、删除和查询功能。另外,当查询到需要信息的时候,系统应提供报表和打印功能,以供公司领导作出决策。
   (3)客户销售管理模块,有基本的添加、修改、删除和查询功能。其目标是提高客户销售数据的准确性、及时性和完整性,对客户销售进行有效管理,提供决策支持所需的数据。
     (4)服务反馈模块,有基本的添加、修改、删除和查询功能,其目标是及时记录客户反馈的信息,提供有竞争力的售后支持、修理和维护服务
 
模型分析:

 

好了 开始写项目吧!
    首先创建django项目:
            环境:Python3
            工具: pycharm
            用到的插件:jquery bootsharp
  • 创建项目:
  • 根据关系编写model 认证方式继承于django自带认证from django.contrib.auth.models import User
  1 from django.db import models
  2 from django.contrib.auth.models import User
  3 # Create your models here.
  4 
  5 
  6 class Customer(models.Model):
  7 \'\'\'客户信息表\'\'\'
  8 name = models.CharField(max_length=32,blank=True,null=True)
  9 qq = models.CharField(max_length=64,unique=True)
 10 qq_name = models.CharField(max_length=64,blank=True,null=True)
 11 phone = models.CharField(max_length=64,blank=True,null=True)
 12 source_choices = ((0,\'转介绍\'),
 13 (1,\'QQ群\'),
 14 (2,\'官网\'),
 15 (3,\'百度推广\'),
 16 (4,\'51CTO\'),
 17 (5,\'知乎\'),
 18 (6,\'市场推广\')
 19 )
 20 
 21 source = models.SmallIntegerField(choices=source_choices)
 22 referral_from = models.CharField(verbose_name="转介绍人qq",max_length=64,blank=True,null=True)
 23 
 24 consult_course = models.ForeignKey("Course",verbose_name="咨询课程")
 25 content = models.TextField(verbose_name="咨询详情")
 26 tags = models.ManyToManyField("Tag",blank=True,null=True)
 27 status_choices = ((0,\'已报名\'),
 28 (1,\'未报名\'),
 29 )
 30 status = models.SmallIntegerField(choices=status_choices,default=1)
 31 consultant = models.ForeignKey("UserProfile")
 32 memo = models.TextField(blank=True,null=True)
 33 date = models.DateTimeField(auto_now_add=True)
 34 
 35 def __str__(self):
 36 return self.qq
 37 
 38 class Meta:
 39 verbose_name ="客户表"
 40 verbose_name_plural ="客户表"
 41 
 42 class Tag(models.Model):
 43 name = models.CharField(unique=True,max_length=32)
 44 
 45 def __str__(self):
 46 return self.name
 47 
 48 class Meta:
 49 verbose_name = "标签"
 50 verbose_name_plural = "标签"
 51 
 52 class CustomerFollowUp(models.Model):
 53 \'\'\'客户跟进表\'\'\'
 54 customer = models.ForeignKey("Customer")
 55 content = models.TextField(verbose_name="跟进内容")
 56 consultant = models.ForeignKey("UserProfile")
 57 
 58 intention_choices = ((0,\'2周内报名\'),
 59 (1,\'1个月内报名\'),
 60 (2,\'近期无报名计划\'),
 61 (3,\'已在其它机构报名\'),
 62 (4,\'已报名\'),
 63 (5,\'已拉黑\'),
 64 )
 65 intention = models.SmallIntegerField(choices=intention_choices)
 66 date = models.DateTimeField(auto_now_add=True)
 67 
 68 def __str__(self):
 69 return "<%s : %s>" %(self.customer.qq,self.intention)
 70 
 71 
 72 class Meta:
 73 verbose_name = "客户跟进记录"
 74 verbose_name_plural = "客户跟进记录"
 75 
 76 class Course(models.Model):
 77 \'\'\'课程表\'\'\'
 78 name = models.CharField(max_length=64,unique=True)
 79 price = models.PositiveSmallIntegerField()
 80 period = models.PositiveSmallIntegerField(verbose_name="周期(月)")
 81 outline = models.TextField()
 82 
 83 def __str__(self):
 84 return self.name
 85 
 86 class Meta:
 87 verbose_name = "课程表"
 88 verbose_name_plural = "课程表"
 89 
 90 class Branch(models.Model):
 91 \'\'\'校区\'\'\'
 92 name = models.CharField(max_length=128,unique=True)
 93 addr = models.CharField(max_length=128)
 94 def __str__(self):
 95 return self.name
 96 
 97 
 98 class Meta:
 99 verbose_name = "校区"
100 verbose_name_plural = "校区"
101 
102 class ClassList(models.Model):
103 \'\'\'班级表\'\'\'
104 branch = models.ForeignKey("Branch",verbose_name="校区")
105 course = models.ForeignKey("Course")
106 class_type_choices = ((0,\'面授(脱产)\'),
107 (1,\'面授(周末)\'),
108 (2,\'网络班\')
109 )
110 class_type = models.SmallIntegerField(choices=class_type_choices,verbose_name="班级类型")
111 semester = models.PositiveSmallIntegerField(verbose_name="学期")
112 teachers = models.ManyToManyField("UserProfile")
113 start_date = models.DateField(verbose_name="开班日期")
114 end_date = models.DateField(verbose_name="结业日期",blank=True,null=True)
115 
116 def __str__(self):
117 return "%s %s %s" %(self.branch,self.course,self.semester)
118 
119 class Meta:
120 unique_together = (\'branch\',\'course\',\'semester\')
121 verbose_name_plural = "班级"
122 verbose_name = "班级"
123 
124 class CourseRecord(models.Model):
125 \'\'\'上课记录\'\'\'
126 from_class = models.ForeignKey("ClassList",verbose_name="班级")
127 day_num = models.PositiveSmallIntegerField(verbose_name="第几节(天)")
128 teacher = models.ForeignKey("UserProfile")
129 has_homework = models.BooleanField(default=True)
130 homework_title = models.CharField(max_length=128,blank=True,null=True)
131 homework_content = models.TextField(blank=True,null=True)
132 outline = models.TextField(verbose_name="本节课程大纲")
133 date = models.DateField(auto_now_add=True)
134 
135 def __str__(self):
136 return "%s %s" %(self.from_class,self.day_num)
137 
138 class Meta:
139 unique_together = ("from_class", "day_num")
140 verbose_name_plural = "上课记录"
141 
142 
143 class StudyRecord(models.Model):
144 \'\'\'学习记录\'\'\'
145 student = models.ForeignKey("Enrollment")
146 course_record = models.ForeignKey("CourseRecord")
147 attendance_choices = ((0,\'已签到\'),
148 (1,\'迟到\'),
149 (2,\'缺勤\'),
150 (3,\'早退\'),
151 )
152 attendance = models.SmallIntegerField(choices=attendance_choices,default=0)
153 score_choices = ((100,"A+"),
154 (90,"A"),
155 (85,"B+"),
156 (80,"B"),
157 (75,"B-"),
158 (70,"C+"),
159 (60,"C"),
160 (40,"C-"),
161 (-50,"D"),
162 (-100,"COPY"),
163 (0,"N/A"),
164 )
165 score = models.SmallIntegerField(choices=score_choices,default=0)
166 memo = models.TextField(blank=True,null=True)
167 date = models.DateField(auto_now_add=True)
168 
169 def __str__(self):
170 return "%s %s %s" %(self.student,self.course_record,self.score)
171 
172 class Meta:
173 unique_together = (\'student\',\'course_record\')
174 verbose_name_plural = "学习记录"
175 
176 
177 class Enrollment(models.Model):
178 \'\'\'报名表\'\'\'
179 customer = models.ForeignKey("Customer")
180 enrolled_class = models.ForeignKey("ClassList",verbose_name="所报班级")
181 consultant = models.ForeignKey("UserProfile",verbose_name="课程顾问")
182 contract_agreed = models.BooleanField(default=False,verbose_name="学员已同意合同条款")
183 contract_approved = models.BooleanField(default=False,verbose_name="合同已审核")
184 date = models.DateTimeField(auto_now_add=True)
185 
186 def __str__(self):
187 return "%s %s" %(self.customer,self.enrolled_class)
188 
189 class Meta:
190 unique_together = ("customer","enrolled_class")
191 verbose_name_plural = "报名表"
192 
193 class Payment(models.Model):
194 \'\'\'缴费记录\'\'\'
195 customer = models.ForeignKey("Customer")
196 course = models.ForeignKey("Course",verbose_name="所报课程")
197 amount = models.PositiveIntegerField(verbose_name="数额",default=500)
198 consultant = models.ForeignKey("UserProfile")
199 date = models.DateTimeField(auto_now_add=True)
200 
201 def __str__(self):
202 return "%s %s" %(self.customer,self.amount)
203 
204 class Meta:
205 verbose_name_plural = "缴费记录"
206 
207 class UserProfile(models.Model):
208 \'\'\'账号表\'\'\'
209 user = models.OneToOneField(User)
210 name = models.CharField(max_length=32)
211 roles = models.ManyToManyField("Role",blank=True,null=True)
212 
213 def __str__(self):
214 return self.name
215 
216 class Role(models.Model):
217 \'\'\'角色表\'\'\'
218 name = models.CharField(max_length=32,unique=True)
219 menus = models.ManyToManyField("Menu",blank=True)
220 
221 def __str__(self):
222 return self.name
223 class Meta:
224 verbose_name_plural = "角色"
225 
226 
227 class Menu(models.Model):
228 \'\'\'菜单\'\'\'
229 name = models.CharField(max_length=32)
230 url_name = models.CharField(max_length=64)
231 
232 def __str__(self):
233 return self.name
models.py

 

  • 注册数据表
crm/admin.py

1 from django.contrib import admin 2 from crm import models 3 4 admin.site.register(models.Customer) 5 admin.site.register(models.CustomerFollowUp) 6 admin.site.register(models.Enrollment) 7 admin.site.register(models.Course) 8 admin.site.register(models.ClassList) 9 admin.site.register(models.CourseRecord) 10 admin.site.register(models.Branch) 11 admin.site.register(models.Role) 12 admin.site.register(models.Payment) 13 admin.site.register(models.StudyRecord) 14 admin.site.register(models.Tag) 15 admin.site.register(models.UserProfile) 16 admin.site.register(models.Menu)

View Code

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吧 

  • 接下来创建几条数据吧! 

数据创建完成了,但是我们发现了一个问题,我们创建了那么多字段为什么只而admin只显示了主键字段,这样的话查看数据就非常的不方便,因此我们就需要对admin进行定制了!
        我们继续修改crm/admin.py
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

     效果显而易见 

 

编写自己的admin 管理系统

 

以上是关于Django CRM客户关系管理系统的主要内容,如果未能解决你的问题,请参考以下文章

Django项目:CRM(客户关系管理系统)--83--73PerfectCRM实现CRM模板统一

Django项目:CRM(客户关系管理系统)--64--54PerfectCRM实现CRM客户报名链接

Django项目:CRM(客户关系管理系统)--70--60PerfectCRM实现CRM学生上课记录

Django项目:CRM(客户关系管理系统)--72--62PerfectCRM实现CRM讲师讲课记录

Django项目:CRM(客户关系管理系统)--46--37PerfectCRM实现CRM用户注册

Django项目:CRM(客户关系管理系统)--75--65PerfectCRM实现CRM课程分数排名