第十九 django繼續及CRM
阿新 • • 發佈:2018-01-30
message big err pps list 新項目 verbose mem files
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