Browse Source

后台编辑字典类型优化

linhaohong 3 months ago
parent
commit
e2c38b8bab
1 changed files with 14 additions and 13 deletions
  1. 14 13
      AdminController/DataDictManageController.py

+ 14 - 13
AdminController/DataDictManageController.py

@@ -261,7 +261,7 @@ class DataDictView(View):
         now_time = int(time.time())
 
         try:
-            if not category_id or not names:
+            if not category_id:
                 return response.json(444)
 
             names = json.loads(names)
@@ -280,18 +280,19 @@ class DataDictView(View):
                 category.updated_by = user_id
                 category.save()
 
-                # 删除原有多语言并重新插入
-                DictCategoryI18n.objects.filter(category=category).delete()
-                for name_entry in names:
-                    DictCategoryI18n.objects.create(
-                        category=category,
-                        lang_code=name_entry["lang"],
-                        name=name_entry["text"],
-                        created_time=now_time,
-                        updated_time=now_time,
-                        created_by=user_id,
-                        updated_by=user_id
-                    )
+                if names:
+                    # 删除原有多语言并重新插入
+                    DictCategoryI18n.objects.filter(category=category).delete()
+                    for name_entry in names:
+                        DictCategoryI18n.objects.create(
+                            category=category,
+                            lang_code=name_entry["lang"],
+                            name=name_entry["text"],
+                            created_time=now_time,
+                            updated_time=now_time,
+                            created_by=user_id,
+                            updated_by=user_id
+                        )
 
                 if not items:
                     return response.json(0)