Преглед изворни кода

Merge branch 'dev' of http://192.168.136.99:3000/SERVER/AnsjerServer into dev

tanghongbin пре 4 година
родитељ
комит
d385d800ec
2 измењених фајлова са 10 додато и 7 уклоњено
  1. 8 5
      Controller/RegionCountryController.py
  2. 2 2
      Model/models.py

+ 8 - 5
Controller/RegionCountryController.py

@@ -34,7 +34,7 @@ class RegionCountryView(View):
         if operation == 'initUserRegion':
             return self.do_initUserRegion(token.userID, request_dict, response)
         elif operation == 'initRegionDate':
-            return self.do_initRegionDate(token.userID, request_dict, response)
+            return self.do_initRegionDate(request_dict, response)
         else:
             return response.json(404)
 
@@ -47,11 +47,13 @@ class RegionCountryView(View):
 
     def do_initRegionDate(self, request_dict, response):
         filepath = request_dict.get('filepath')
-        fobj = open(filepath)
-        region_list = json.loads(fobj)
 
-        now_time = int(time.time())
+        with open(filepath, 'r', encoding='UTF-8') as f:
+            region_list = json.load(f)
 
+        #region_list = json.loads(fobj)
+        now_time = int(time.time())
+        regin_list = []
         for region in region_list:
             name = region['name']
             region_id = region['region_id']
@@ -61,5 +63,6 @@ class RegionCountryView(View):
                 cn = countries['cn']
                 en = countries['en']
                 number = countries['number']
+                regin_list.append(RegionCountryModel(number=number, region_id=region_id, name=name, cn=cn, en=en, add_time=now_time, update_time=now_time))
 
-                RegionCountryModel.objects.create(number=number, region_id=region_id, name=name, cn=cn, en=en, add_time=now_time, update_time=now_time)
+        RegionCountryModel.objects.bulk_create(regin_list)

+ 2 - 2
Model/models.py

@@ -121,8 +121,8 @@ class Role(models.Model):
 
 class RegionCountryModel(models.Model):
     number = models.IntegerField(primary_key=True, verbose_name='唯一标识')
-    region_id = models.IntegerField(unique=True, verbose_name='大洲编号')
-    name = models.CharField(unique=True, max_length=50, verbose_name=u'名称')
+    region_id = models.IntegerField(verbose_name='大洲编号')
+    name = models.CharField(max_length=50, verbose_name=u'名称')
     cn = models.CharField(blank=True, max_length=64, verbose_name=u'中文名称')
     en = models.CharField(blank=True, max_length=64, verbose_name=u'英文名称')
     add_time = models.IntegerField(default=0, verbose_name='添加时间')