Browse Source

路径存在则更新 不存在则新增

peng 2 năm trước cách đây
mục cha
commit
7965c865d6
1 tập tin đã thay đổi với 10 bổ sung7 xóa
  1. 10 7
      controller/LangAVSSController.py

+ 10 - 7
controller/LangAVSSController.py

@@ -206,13 +206,16 @@ class LangAVSSView(TemplateView):
                 for location in locations:
                     # print(location['filename'])
                     # print(location['line'])
-
-                    locationValue = {
-                        'lk': lkModel,
-                        'filename': location['filename'],
-                        'line': location['line']
-                    }
-                    LangLocationModel.objects.create(**locationValue)
+                    langlocation = LangLocationModel.objects.filter(lk=lkModel.id, filename=location['filename'])
+                    if langlocation.exists():
+                        langlocation.update(line=location['line'])
+                    else:
+                        locationValue = {
+                            'lk': lkModel,
+                            'filename': location['filename'],
+                            'line': location['line']
+                        }
+                        LangLocationModel.objects.create(**locationValue)
             return response.json(0)
         else:
             return response.json(444)