码迷,mamicode.com
首页 > 其他好文 > 详细

第十九 django继续及CRM

时间:2018-01-30 12:15:16      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:ken   integer   span   课程   self   sch   文件   bubuko   周末   

 1.创建新项目

技术分享图片

2.设计数据库表

 技术分享图片

from django.db import models

# Create your models here.
from django.contrib.auth.models import User

course_type_choices = ((online, 网络班),
                       (offline_weekend, 面授班(周末),
                       (offline_fulltime, 面授班(脱产)),
                       )

class School(models.Model):
    name = models.CharField(max_length=128,unique=True)
    city = models.CharField(max_length=64)
    addr = models.CharField(max_length=128)

    def __unicode__(self):
        return self.name

class UserProfile(models.Model):
    User = models.OneToOneField(User)
    name = models.CharField(max_length=64)
    school = models.ForeignKey(School)

    def __unicode__(self):
        return self.name

class Customer(models.Model):
    qq = models.CharField(max_length=64,unique=True)
    name = models.CharField(max_length=32,blank=True,null=True)
    phone = models.BigIntegerField(blank=True,null=True)
    course = models.ForeignKey(Course)
    course_type = models.CharField(max_length=64,choices=course_type_choices,default=offline_weekend)
    consult_memo = models.TextField()
    source_type_choices = ((qq,qq群),
                           (referral,内部转介绍),
                           (agent,‘‘),
                           (others,其它),
                           )
    source_type = models.CharField(max_length=64,choices=source_type_choices,default=qq)
    referral_from = models.ForeignKey(self,blank=True,null=True)
    status_choices = ((signed,已报名),
                      (unregistered,未报名),
                      (graduated,已毕业),
                      (drop-off,退学),
                      )
    status = models.CharField(max_length=64,choices=status_choices,default=signed)
    consultant = models.ForeignKey(UserProfile)
    class_list = models.ManyToManyField(ClassList,blank=True)
    date = models.DateField(咨询日期,auto_now_add=True)

    def __unicode__(self):
        return "%s (%s)" %(self.qq,self.name)


class CustomerTrackRecord(models.Model):
    customer = models.ForeignKey(Customer)
    track_record = models.TextField(跟踪记录)
    track_date = models.DateField()
    follower = models.ForeignKey(UserProfile)
    status_choices = ((1,近期无报名计划),
                      (2,2个月内报名计划),
                      (3,1个月内报名计划),
                      (4,2周内报名计划),
                      (5,1周内报名计划),
                      (6,2天内报名),
                      (7,已报名),
                      )
    status = models.IntegerField(状态,choices=status_choices,help_text=选择此客户的原因)

    def __unicode__(self):
        return self.customer

class Course(models.Model):
    name = models.CharField(max_length=64,unique=True)
    online_price = models.IntegerField()
    offline_price = models.IntegerField()
    introduction = models.TextField()

    def __unicode__(self):
        return self.name

class ClassList(models.Model):
    course = models.ForeignKey(Course,verbose_name=课程)
    semester = models.IntegerField(verbose_name=学期)
    course_type = models.CharField(max_length=64, choices=course_type_choices, default=offline_weekend)
    teachers = models.ManyToManyField(UserProfile)
    start_date = models.DateField()
    graduate_date = models.DateField()

    def __unicode__(self):
        return "%s(%s) %s" %(self.course.name,self.course_type,self.semester)

    class Meta:
        unique_together = (course,semester,course_type)

class CourseRecord(models.Model):
    class_obj = models.ForeignKey(ClassList)
    day_num = models.IntegerField("第几节课")
    course_date = models.DateField(auto_now_add=True,verbose_name=上课时间)
    teacher = models.ForeignKey(UserProfile)

    def __unicode__(self):
        return self.class_obj,self.day_num

    class Meta:
        unique_together = (class_obj,day_num)

class StudyRecord(models.Model):
    course_record = models.ForeignKey(CourseRecord)
    student = models.ForeignKey(Customer)
    record_choices = ((checked,已签到),
                      (late,迟到),
                      (noshow,缺勤),
                      (leave_early,早退)
                      )
    record = models.CharField("状态",choices=record_choices,max_length=64)
    score_choices = ((100,A+),
                     (90,A),
                     (80,A-),
                     (70,B+),
                     (60,B),
                     (50,C),
                     (40,C-),
                     (0,D),
                     (-1,N/A),
                     (-100,COPY),
                     (-1000,FAIL)
                     )
    score = models.IntegerField("本节成绩",choices=score_choices,default=-1)
    date = models.DateTimeField(auto_now_add=True)
    note = models.CharField(备注,max_length=255,blank=True,null=True)

    def __unicode__(self):
        return "%s %s %s" %(self.course_record,self.student,self.record)

3.生成表

3.1.配置引入mysql

技术分享图片

import pymysql
pymysql.install_as_MySQLdb()

3.2.配置数据库连接文件

....
INSTALLED_APPS = [
    django.contrib.admin,
    django.contrib.auth,
    django.contrib.contenttypes,
    django.contrib.sessions,
    django.contrib.messages,
    django.contrib.staticfiles,
    cklcrm.apps.CklcrmConfig,
]
....
DATABASES = {
    # ‘default‘: {
    #     ‘ENGINE‘: ‘django.db.backends.sqlite3‘,
    #     ‘NAME‘: os.path.join(BASE_DIR, ‘db.sqlite3‘),
    # }
    default: {
        ENGINE: django.db.backends.mysql,
        NAME: cklcrm,
        HOST: 192.168.1.80,
        PORT: ‘‘,
        USER: sayyou,
        PASSWORD: what@F893,
    }
}
....

3.3.生成表

技术分享图片

技术分享图片

4.创建admin

4.1.admin创建登录用户

技术分享图片

4.2.注册表到admin

技术分享图片

from django.contrib import admin
import cklcrm.models
# Register your models here.

admin.site.register(cklcrm.models.UserProfile)
admin.site.register(cklcrm.models.Customer)
admin.site.register(cklcrm.models.CustomerTrackRecord)
admin.site.register(cklcrm.models.ClassList)
admin.site.register(cklcrm.models.Course)
admin.site.register(cklcrm.models.CourseRecord)
admin.site.register(cklcrm.models.StudyRecord)
admin.site.register(cklcrm.models.School)

4.3.启动服务

技术分享图片

4.4.登录admin

技术分享图片

技术分享图片

 

第十九 django继续及CRM

标签:ken   integer   span   课程   self   sch   文件   bubuko   周末   

原文地址:https://www.cnblogs.com/ckl893/p/8383519.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!