修复BUG: 新增导入和导入更新bug优化

pull/84/head
猿小天 2023-01-04 17:48:37 +08:00
parent c0ed29dea2
commit 5861f7dac2
1 changed files with 4 additions and 0 deletions

View File

@ -18,6 +18,10 @@ def import_to_data(file_url, field_data, m2m_fields=None):
file_path_dir = os.path.join(settings.BASE_DIR, file_url) file_path_dir = os.path.join(settings.BASE_DIR, file_url)
workbook = openpyxl.load_workbook(file_path_dir) workbook = openpyxl.load_workbook(file_path_dir)
table = workbook[workbook.sheetnames[0]] table = workbook[workbook.sheetnames[0]]
theader = tuple(table.values)[0] # Excel的表头
is_update = '更新主键(勿改)' in theader # 是否导入更新
if is_update is False: # 不是更新时,删除id列
field_data.pop('id')
# 获取参数映射 # 获取参数映射
validation_data_dict = {} validation_data_dict = {}
for key, value in field_data.items(): for key, value in field_data.items():