优化:导入模板优化
parent
fc33d271d8
commit
799642f1b1
|
@ -35,9 +35,10 @@ def import_to_data(file_url, field_data, m2m_fields=None):
|
||||||
for k, v in choices.get("data").items():
|
for k, v in choices.get("data").items():
|
||||||
data_dict[k] = v
|
data_dict[k] = v
|
||||||
elif choices.get("queryset") and choices.get("values_name"):
|
elif choices.get("queryset") and choices.get("values_name"):
|
||||||
data_list = choices.get("queryset").values(choices.get("values_name"), "id")
|
data_list = choices.get("queryset").values(choices.get("values_name"),
|
||||||
|
choices.get("values_value", "id"))
|
||||||
for ele in data_list:
|
for ele in data_list:
|
||||||
data_dict[ele.get(choices.get("values_name"))] = ele.get("id")
|
data_dict[ele.get(choices.get("values_name"))] = ele.get(choices.get("values_value", "id"))
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
validation_data_dict[key] = data_dict
|
validation_data_dict[key] = data_dict
|
||||||
|
@ -58,7 +59,6 @@ def import_to_data(file_url, field_data, m2m_fields=None):
|
||||||
if cell_value is None or cell_value == '':
|
if cell_value is None or cell_value == '':
|
||||||
continue
|
continue
|
||||||
elif value_type == 'date':
|
elif value_type == 'date':
|
||||||
print(61, datetime.strptime(str(cell_value), '%Y-%m-%d %H:%M:%S').date())
|
|
||||||
try:
|
try:
|
||||||
cell_value = datetime.strptime(str(cell_value), '%Y-%m-%d %H:%M:%S').date()
|
cell_value = datetime.strptime(str(cell_value), '%Y-%m-%d %H:%M:%S').date()
|
||||||
except:
|
except:
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
from types import FunctionType, MethodType
|
||||||
from urllib.parse import quote
|
from urllib.parse import quote
|
||||||
|
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
|
@ -68,6 +69,8 @@ class ImportSerializerMixin:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
assert self.import_field_dict, "'%s' 请配置对应的导出模板字段。" % self.__class__.__name__
|
assert self.import_field_dict, "'%s' 请配置对应的导出模板字段。" % self.__class__.__name__
|
||||||
|
if isinstance(self.import_field_dict, MethodType) or isinstance(self.import_field_dict, FunctionType):
|
||||||
|
self.import_field_dict = self.import_field_dict()
|
||||||
# 导出模板
|
# 导出模板
|
||||||
if request.method == "GET":
|
if request.method == "GET":
|
||||||
# 示例数据
|
# 示例数据
|
||||||
|
|
Loading…
Reference in New Issue