前端模板
models.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | #_*_coding:utf-8_*_ from django.db import models # Create your models here. from django.core.exceptions import ValidationError from django.db import models from django.contrib.auth.models import User course_type_choices = (( 'online' ,u '网络班' ), ( 'offline_weekend' ,u '面授班(周末)' ,), ( 'offline_fulltime' ,u '面授班(脱产)' ,), ) 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 __str__( self ): return self .name class UserProfile(models.Model): user = models.OneToOneField(User) #alex name = models.CharField(max_length = 64 ) school = models.ForeignKey( 'School' ) def __str__( 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' ,u "qq群" ), ( 'referral' ,u "内部转介绍" ), ( '51cto' ,u "51cto" ), ( 'agent' ,u "招生代理" ), ( 'others' ,u "其它" ), ) source_type = models.CharField(max_length = 64 ,choices = source_type_choices) referral_from = models.ForeignKey( 'self' ,blank = True ,null = True ,related_name = "referraled_who" ) status_choices = (( 'signed' ,u "已报名" ), ( 'unregistered' ,u "未报名" ), ( 'graduated' ,u "已毕业" ), ( 'drop-off' ,u "退学" ), ) status = models.CharField(choices = status_choices,max_length = 64 ) consultant = models.ForeignKey( 'UserProfile' ,verbose_name = u "课程顾问" ) class_list = models.ManyToManyField( "ClassList" ,blank = True ) date = models.DateField(u "咨询日期" ,auto_now_add = True ) def __str__( self ): return "%s(%s)" % ( self .qq, self .name) class CustomerTrackRecord(models.Model): customer = models.ForeignKey(Customer) track_record = models.TextField(u "跟踪纪录" ) track_date = models.DateField(auto_now_add = True ) follower = models.ForeignKey(UserProfile) status_choices = (( 1 ,u "近期无报名计划" ), ( 2 ,u "2个月内报名" ), ( 3 ,u "1个月内报名" ), ( 4 ,u "2周内报名" ), ( 5 ,u "1周内报名" ), ( 6 ,u "2天内报名" ), ( 7 ,u "已报名" ), ) status = models.IntegerField(u "状态" ,choices = status_choices,help_text = u "选择客户此时的状态" ) def __str__( 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 __str__( self ): return self .name class ClassList(models.Model): course = models.ForeignKey(Course,verbose_name = u "课程" ) semester = models.IntegerField(verbose_name = u "学期" ) 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 __str__( 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(u "第几节课" ) course_date = models.DateField(auto_now_add = True ,verbose_name = u "上课时间" ) teacher = models.ForeignKey(UserProfile) #students = models.ManyToManyField(Customer) def __str__( self ): return "%s,%s" % ( 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' , u "已签到" ), ( 'late' ,u "迟到" ), ( 'noshow' ,u "缺勤" ), ( 'leave_early' ,u "早退" ), ) record = models.CharField(u "状态" , choices = record_choices,max_length = 64 ) score_choices = (( 100 , 'A+' ), ( 90 , 'A' ), ( 85 , 'B+' ), ( 80 , 'B' ), ( 70 , 'B-' ), ( 60 , 'C+' ), ( 50 , 'C' ), ( 40 , 'C-' ), ( 0 , 'D' ), ( - 1 , 'N/A' ), ( - 100 , 'COPY' ), ( - 1000 , 'FAIL' ), ) score = models.IntegerField(u "本节成绩" ,choices = score_choices,default = - 1 ) date = models.DateTimeField(auto_now_add = True ) note = models.CharField(u "备注" ,max_length = 255 ,blank = True ,null = True ) def __str__( self ): return "%s,%s,%s" % ( self .course_record, self .student, self .record) |
一、静态文件目录设置
在settings.py文件中加入:
1 2 3 4 | STATIC_URL = '/static/' STATICFILES_DIRS = ( os.path.join(BASE_DIR, 'static' ), ) |
STATIC_URL为静态文件目录的别名,引用静态文件方法:
STATICFILES_DIRS为静态文件实际目录,其中可以有多个路径
二、bootstrap模板
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | < table class = "table table-hover" > < thead > < tr > < th >ID</ th > < th >QQ</ th > < th >姓名</ th > < th >渠道</ th > < th >咨询课程</ th > < th >课程类型</ th > < th >客户备注</ th > < th >状态</ th > < th >课程顾问</ th > < th >日期</ th > </ tr > </ thead > < tbody > {% for customer in custmer_list %} < tr > < td >{{ customer.id }}</ td > < td >{{ customer.qq }}</ td > < td >{{ customer.name }}</ td > < td >{{ customer.get_source_type_display }}</ td >} < td >{{ customer.course }}</ td > < td >{{ customer.get_course_type_display }}</ td > < td >{{ customer.consult_memo | truncatechars:20 }}</ td > < td class = "{{ customer.status }}" >{{ customer.get_status_display }}</ td > < td >{{ customer.consultant }}</ td > < td >{{ customer.date }}</ td > </ tr > {% endfor %} </ tbody > </ table > |
get_source_type_display作用是: