Django项目:CRM(客户关系管理系统)--11--04PerfectCRM实现King_admin注册功能03

 

 1 #base_admin.py
 2 #Django admin 注册功能的形式
 3 # sites = {
 4 #     'crm':{
 5 #         'customers':CustomerAdmin,
 6 #         'customerfollowup':CustomerFollowUPAdmin,
 7 #     }
 8 # }
 9 
10 class AdminRegisterException(Exception):  #自定义异常
11     def __init__(self,msg):
12         self.message = msg
13 
14 class BaseAdmin(object):#自定义方法
15     list_display = ()
16 
17 registered_sites={}
18 def register(model,admin_class=None): #默认值None 使用 BaseAdmin
19     app_name = model._meta.app_label#用内置方法获取 APP名字 (crm)
20     model_name = model._meta.model_name#用内置方法获取 表名  (Customer)
21     if app_name not in registered_sites:
22         registered_sites[app_name] = {} #创建  crm={}
23     if model_name in registered_sites[app_name]:
24         raise AdminRegisterException("app [%s] model [%s] has already registered!异常"
25                                              %(app_name,model_name))#自定义异常
26     if not admin_class:
27         admin_class = BaseAdmin  #默认值None 使用class BaseAdmin
28     registered_sites[app_name][model_name] = admin_class #注册APP
#base_admin.py

 

 

 

 1 #kingadmin.py
 2 # ————————04PerfectCRM实现King_admin注册功能————————
 3 from crm import models
 4 #print("kingadmin crm",models.Customer)
 5 from king_admin.base_admin import register,BaseAdmin
 6 
 7 #04客户信息表
 8 class CustomerAdmin(BaseAdmin):#定制Djanago admin
 9     list_display = ('id', 'qq', 'source', 'consultant', 'content', 'date')  # 显示字段表头
10 
11 
12 register(models.Customer,CustomerAdmin)
13 register(models.CourseRecord)
14 
15 
16 # ————————04PerfectCRM实现King_admin注册功能————————
#kingadmin.py

 

 

 

 

 1 #views.py
 2 from django.shortcuts import render
 3 
 4 # from django import conf #配置文件
 5 # print("dj conf:",conf) #配置文件
 6 # print("dj conf:",conf.settings)#配置文件.设置
 7 
 8 from king_admin import app_config #自动调用  动态加载类和函数
 9 
10 from king_admin.base_admin import registered_sites # registered_sites={}
11 
12 def app_index(request):
13     # for app in conf.settings.INSTALLED_APPS:
14     #     print(app)#循环打印 配置文件.设置.安装应用程序#.Perfectcustomer\settings里的INSTALLED_APPS列表
15 
16     print("registered_sites",registered_sites)
17     return render(request, 'king_admin/app_index.html')
#views.py

 

 

 

 

 

 1 #views.py
 2 from django.shortcuts import render
 3 
 4 # from django import conf #配置文件
 5 # print("dj conf:",conf) #配置文件
 6 # print("dj conf:",conf.settings)#配置文件.设置
 7 
 8 from king_admin import app_config #自动调用  动态加载类和函数
 9 
10 # from king_admin.base_admin import registered_sites # registered_sites={}
11 from king_admin import base_admin
12 
13 def app_index(request):
14     # for app in conf.settings.INSTALLED_APPS:
15     #     print(app)#循环打印 配置文件.设置.安装应用程序#.Perfectcustomer\settings里的INSTALLED_APPS列表
16 
17     # print("registered_sites",registered_sites)
18     # return render(request, 'king_admin/app_index.html')
19 
20     print("registered_sites", base_admin.registered_sites)
21     return render(request, 'king_admin/app_index.html')
#views.py

 

 

 


 

如果感觉本章博客对您有帮助,请尽情打赏吧!

 

posted @ 2018-03-21 11:35  颜言  阅读(643)  评论(0编辑  收藏  举报