Diango---CRM專案實戰
阿新 • • 發佈:2020-08-11
上來廢話不多說直接開始寫
from django.db import models from django.contrib.auth.models import User # Create your models here. ''' choices Admin中顯示選擇框的內容,用不變動的資料放在記憶體中從而避免跨表操作 如:gf = models.IntegerField(choices=[(0, '何穗'),(1, '大表姐'),],default=1) ''' '''客戶資訊表''' class Customer(models.Model): name=models.CharField(max_length=32,blank=True,null=True)# blank Admin中是否允許使用者輸入為空 qq=models.CharField(max_length=64,unique=True)#unique 資料庫中欄位是否可以建立唯一索引 qq_name=models.CharField(max_length=64,blank=True,null=True) phone=models.CharField(max_length=64,blank=True,null=True) source_choice=((0,'轉介紹'), (1,'QQ'), (2,'微信'), (3,'官網'), ) source=models.SmallIntegerField(choices=source_choice) referral_from=models.CharField(verbose_name="轉介紹人QQ",max_length=64,blank=True,null=True)# verbose_name Admin中顯示的欄位名稱 consult_course=models.ForeignKey("Course",on_delete=models.CASCADE,verbose_name="諮詢課程") content=models.TextField(verbose_name="諮詢詳情") tags=models.ManyToManyField("Tag",blank=True,null=True) consultant=models.ForeignKey("UserProfile",on_delete=models.CASCADE) memo=models.TextField(blank=True,null=True) date=models.DateTimeField(auto_now_add=True)#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",on_delete=models.CASCADE) content=models.TextField(verbose_name="跟進內容") consultant=models.ForeignKey("UserProfile",on_delete=models.CASCADE) intention_choice=((0,'2周內報名'), (1,'一個月內報名'), (2,'近期無報名計劃'), ) intention=models.SmallIntegerField(choices=intention_choice) 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,null=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='校區',on_delete=models.CASCADE) course=models.ForeignKey("Course",on_delete=models.CASCADE) class_type_choice=((0,'面授(脫產)'), (1,'面授(週末)'), (2,'網路版'), ) class_type=models.SmallIntegerField(choices=class_type_choice,verbose_name='班級型別') semester=models.PositiveSmallIntegerField(verbose_name="學期") teacher=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 = "班級表" verbose_name_plural = "班級表" '''上課記錄表''' class CourseRecord(models.Model): from_class=models.ForeignKey("ClassList",verbose_name="班級",on_delete=models.CASCADE) day_num=models.PositiveSmallIntegerField(verbose_name="第幾節(天)") teacher=models.ForeignKey("UserProfile",on_delete=models.CASCADE) has_homework=models.BooleanField(default=True) homeword_title=models.CharField(max_length=128,blank=True,null=True) homeword_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 = "上課記錄表" verbose_name_plural = "上課記錄表" '''學習記錄表''' class StudentRecord(models.Model): student=models.ForeignKey("Enrollment",on_delete=models.CASCADE) course_record=models.ForeignKey("CourseRecord",on_delete=models.CASCADE) attendance_choices=((0,'已簽到'), (1,'遲到'), (2,'缺勤'), (3,'早退'), ) attendance=models.SmallIntegerField(choices=attendance_choices,default=0) score_choice=((100,"A+"), (90,"A"), (85,"B+"), (80,"B"), (75,"B-"), (70,"C+"), (60,"C"), (40,"C-"), (-50,"D"), (0,"N/A"), ) score=models.SmallIntegerField(choices=score_choice) 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="學習記錄表" verbose_name_plural="學習記錄表" '''報名表''' class Enrollment(models.Model): customer=models.ForeignKey("Customer",on_delete=models.CASCADE) enrolled_class=models.ForeignKey("ClassList",verbose_name="所報班級",on_delete=models.CASCADE) consultant=models.ForeignKey("UserProfile",verbose_name="課程顧問",on_delete=models.CASCADE) contract_agreed=models.BooleanField(default=False,verbose_name="學員已接受合同條款") contract_approvaed=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 = "客戶表" verbose_name_plural = "客戶表" '''繳費紀錄表''' class Payment(models.Model): customer=models.ForeignKey("Customer",on_delete=models.CASCADE) course=models.ForeignKey("Course",verbose_name="所報課程",on_delete=models.CASCADE) amount=models.PositiveSmallIntegerField(verbose_name="數額",default=500) consultant=models.ForeignKey("UserProfile",on_delete=models.CASCADE) 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,on_delete=models.CASCADE) name=models.CharField(max_length=32) roles=models.ManyToManyField("Role",blank=True,null=True) class Meta: verbose_name_plural='賬號資訊表' '''角色表''' class Role(models.Model): name=models.CharField(max_length=32,unique=True) menu=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
- 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
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 155
- 156
- 157
- 158
- 159
- 160
- 161
- 162
- 163
- 164
- 165
- 166
- 167
- 168
- 169
- 170
- 171
- 172
- 173
- 174
- 175
- 176
- 177
- 178
- 179
- 180
- 181
- 182
- 183
- 184
- 185
- 186
- 187
- 188
- 189
二、劃分目錄,各司其職
將專案中urls.py移動至crm的app中
此時寫的url路徑只需寫道crm下的urls.py即可
三、寫前端內容(本專案實戰所需前端在下面連線)
連結:https://pan.baidu.com/s/1nDFGRpMJswVkktOyGwYMgQ
提取碼:ni1r
將檔案中html複製到base.html中,將其中的body部分寫到index.html中,引入
設定css,js儲存路徑
新建目錄statics
設定setting
在statics中建立基本所需目錄
將我上述模板中的js和css進行分類到其中
將js引入到base.html
index.html每個不同使用者登入顯示不同內容
使左側連線能點(從資料庫動態獲取)
注:request.user是拿到就是這個使用者
別名(name=“xxx”)
在網頁模板中,可以很方便的使用。
不帶引數的:
{% url 'name' %}
帶引數的:引數可以是變數名
{% url 'name' 引數 %}
**例如:**
urlpatterns = [
url(r'^$', calc_views.index, name='home'),
url(r'^add/$', calc_views.add, name='add'),
url(r'^add/(\d+)/(\d+)/$', calc_views.add2, name='add2'),
url(r'^admin/', admin.site.urls),
]
<a href="{% url 'add2' 4 5 %}">link</a>
上面的程式碼渲染成最終的頁面是
<a href="/add/4/5/">link</a>
這樣就可以通過 {% url 'add2' 4 5 %} 獲取到對應的網址 /add/4/5/