excel 文件的導入
1.\extra_apps\xadmin\plugins下,添加一個文件 excel.py 添加以下代碼:
import xadmin
from xadmin.views import BaseAdminPlugin,ListAdminView
from django.template import loader
# excel 導入
class ListImportExclePlugin(BaseAdminPlugin):
import_excel = False
def init_request(self, *args, **kwargs):
return bool(self.import_excel)
def block_top_toolbar(self,context,nodes):
nodes.append(loader.render_to_string('xadmin/excel/model_list.top_toolbar.import.html',context_install'''后面還沒寫完'''))
xadmin.site.register_plugin(ListImportExclePlugin,ListAdminView)
2.進入需要進入的app里面的adminx.py 文件里面,在該類里面添加:
import_excel = True
3.在extra_apps/xadmin/templates/xadmin下,在添加一個文件夾,在該文件夾下面,創建一個model_list.top_toolbar.import.html的文件
在該問文件里面填寫代碼:
由於時間的關系,我沒寫,在這里,主要整理思路
4.在該app 下的adminx.py 的該類中,添加
def post(self,request,*args,**kwargs):
if 'excel' in request.FILES:
pass
return super(CoursesAdmin,self).post(request,args,kwargs)