From b18e35b3881c20b008c1be6e2e72c5b47227e618 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8C=BF=E5=B0=8F=E5=A4=A9?= <1638245306@qq.com> Date: Thu, 17 Nov 2022 17:12:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=8A=9F=E8=83=BD:=20=E9=A1=B6?= =?UTF-8?q?=E9=83=A8=E5=8A=A0=E5=85=A5=E6=B6=88=E6=81=AF=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E5=9B=BE=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/application/routing.py | 3 --- backend/application/settings.py | 3 ++- backend/dvadmin/utils/import_export_mixin.py | 7 ++++++- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/backend/application/routing.py b/backend/application/routing.py index d11f6e6..237e5d1 100644 --- a/backend/application/routing.py +++ b/backend/application/routing.py @@ -1,8 +1,5 @@ # -*- coding: utf-8 -*- - - from django.urls import path - from application.websocketConfig import MegCenter websocket_urlpatterns = [ diff --git a/backend/application/settings.py b/backend/application/settings.py index 93e0127..61adde3 100644 --- a/backend/application/settings.py +++ b/backend/application/settings.py @@ -93,6 +93,7 @@ TEMPLATES = [ WSGI_APPLICATION = "application.wsgi.application" + # Database # https://docs.djangoproject.com/en/3.2/ref/settings/#databases @@ -168,7 +169,7 @@ CORS_ALLOW_CREDENTIALS = True # 指明在跨域访问中,后端是否支持 # ================================================= # # ********************* channels配置 ******************* # # ================================================= # -ASGI_APPLICATION = 'application.routing.application' +ASGI_APPLICATION = 'application.asgi.application' CHANNEL_LAYERS = { "default": { "BACKEND": "channels.layers.InMemoryChannelLayer" diff --git a/backend/dvadmin/utils/import_export_mixin.py b/backend/dvadmin/utils/import_export_mixin.py index 1936624..9346661 100644 --- a/backend/dvadmin/utils/import_export_mixin.py +++ b/backend/dvadmin/utils/import_export_mixin.py @@ -7,6 +7,7 @@ from openpyxl import Workbook from openpyxl.worksheet.datavalidation import DataValidation from openpyxl.utils import get_column_letter, quote_sheetname from openpyxl.worksheet.table import Table, TableStyleInfo +from rest_framework.decorators import action from rest_framework.request import Request from dvadmin.utils.import_export import import_to_data @@ -56,6 +57,7 @@ class ImportSerializerMixin: length += 2.1 if ord(char) > 256 else 1 return round(length, 1) if length <= self.export_column_width else self.export_column_width + @action(methods=['get','post'],detail=False) @transaction.atomic # Django 事务,防止出错 def import_data(self, request: Request, *args, **kwargs): """ @@ -151,8 +153,11 @@ class ImportSerializerMixin: if queryset.model._meta.unique_together: # 判断是否存在联合主键 filter_dic = {i: ele.get(i) for i in list(queryset.model._meta.unique_together[0])} else: - filter_dic = {i: ele.get(i) for i in list(set(self.import_field_dict.keys()) & set(unique_list))} + filter_dic = {i: ele.get(i) for i in list(set(unique_list)) if ele.get(i) is not None} instance = filter_dic and queryset.filter(**filter_dic).first() + print(unique_list) + print(filter_dic) + print(instance) if instance and not updateSupport: continue if not filter_dic: