CRM 项目思路解析笔记
urls.py:
from django.conf.urls import url,include
from django.contrib import admin
from LuffyCRM import views
urlpatterns = [
url(r'^admin/', admin.site.urls), #管理员后台登录url
url(r'^$', views.index),
url(r'^crm/',include("crm.urls") ),
url(r'^luffyadmin/',include("luffyAdmin.urls") ),#CRM表后台处理界面
url(r'^account/login/$', views.account_login), #账户登录url--->登录成功后,跳转到index界面 http://127.0.0.1:8000/
url(r'^account/logout/$', views.account_logout,name="logout"),#账户登出url
]
- ^admin/
- ^$
- ^crm/ ^customer_list/$ [name='customer_list']
- ^luffyadmin/
- ^account/login/$
- ^account/logout/$ [name='logout'
http://127.0.0.1:8000/luffyadmin/ ---> luffyAdmin.urls
----->
from django.conf.urls import url,include
from luffyAdmin import views
urlpatterns = [
url(r'^$', views.app_index),# luffyAdmin后台登录主界面
url(r'(\w+)/(\w+)/$', views.model_table_list,name="model_table_list"),#luffyAdmin动态匹配表处理url
]
luffyadmin/views.py:
def model_table_list(request, app_name, model_name):
if app_name in site.registered_admins: #registered_admins 负责把每个App下的表注册self.registered_admins集合里,
#注册的admin list: {'crm': {'customer': <class 'crm.luffy_admin.CustomerAdmin'>, 'course': <class 'crm.luffy_admin.CourseAdmin'>, 'classlist': <class 'luffyAdmin.admin_base.BaseAdmin'>}, 'teacher': {'teachertest':
<class 'luffyAdmin.admin_base.BaseAdmin'>}} ‘app_name’:{model_name}
if model_name in site.registered_admins[app_name]:
admin_class = site.registered_admins[app_name][model_name]
#print("--model class",model_class,locals())
querysets,filter_conditions = get_filter_objs(request,admin_class) #get_filter_objs,返回filter的结果queryset
paginator = Paginator(querysets, admin_class.list_per_page) # Show 25 contacts per page
page = request.GET.get('_page')
try:
querysets = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
querysets = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
querysets = paginator.page(paginator.num_pages)
return render(request,"luffyadmin/model_table_list.html",locals())