Przeglądaj źródła

系通管理上传图片

Your Name 5 lat temu
rodzic
commit
b4554dd637
2 zmienionych plików z 36 dodań i 17 usunięć
  1. 2 3
      apps/AppInfo/models.py
  2. 34 14
      apps/Equipment/views.py

+ 2 - 3
apps/AppInfo/models.py

@@ -886,9 +886,8 @@ class Relations(models.Model):
 
 # 轮播图和广告图
 class SystemPhoto(models.Model):
-    name = models.CharField(u'图片名称', max_length=100, blank=True, null=True)
-    pic_1 = models.CharField(u'轮播图', max_length=100, blank=True, null=True)
-    pic_2 = models.CharField(u'广告图', max_length=100, blank=True, null=True)
+    code = models.CharField(u'图片区分', max_length=5, blank=True, null=True)
+    pic_img = models.CharField(u'图片链接', max_length=100, blank=True, null=True)
     upl_time = models.DateTimeField(u'创建时间', default=timezone.now)
 
     class Meta:

+ 34 - 14
apps/Equipment/views.py

@@ -4608,14 +4608,31 @@ class System_Photo(ListView):
     def get(self,request):
         return render(request, 'backstageNet/systemSet/imageUpload.html', context={})
     def post(self,request):
-        
+
         basestr = request.FILES.get("upload")
-        base_dir = 'media/uploads/'
+        basestr1 = request.FILES.get("upload1")
         now_time = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time()))
         if basestr:
+            base_dir = 'media/uploads/'
             img = Image.open(basestr)
-            img.save(base_dir + now_time +".png")
-            SystemPhoto.objects.create(name=base_dir +now_time +".png",pic_1=base_dir +now_time +".png")
+            code = 1
+        else:
+            base_dir = 'media/uploads1/'
+            code = 2
+            img = Image.open(basestr1)
+        img.save(base_dir + now_time +".png")
+        pic_list = SystemPhoto.objects.filter(code=code).order_by("-upl_time")
+        if code == 1:
+            if pic_list and len(pic_list) <=2:
+                SystemPhoto.objects.create(code=code,pic_img=base_dir +now_time +".png")
+            else:
+                pic_list.first().updata(pic_img=base_dir +now_time +".png")
+        else:
+            if pic_list and len(pic_list) <=3:
+                SystemPhoto.objects.create(code=code,pic_img=base_dir +now_time +".png")
+            else:
+                pic_list.first().updata(pic_img=base_dir +now_time +".png")
+        
         return HttpResponse("1")
     
 
@@ -4623,14 +4640,17 @@ class System_Photo(ListView):
 
 # 系统管理上传图片
 class System_Photo_Save(ListView):
-    def get(self,request):
-        pass
     def post(self,request):
-        pic_1 = request.POST.get('pic_1')
-        pic_2 = request.POST.get('pic_2')
-        if pic_1:
-            name = pic_1
-        elif pic_2:
-            name = pic_2
-        SystemPhoto.objects.create(name=name,pic_1=pic_1,pic_2=pic_2)
-        return HttpResponse("1")
+        code = request.POST.get("code")
+        data = []
+        if code != "1" and code != "2":
+            return HttpResponse("0")
+        else:
+           pic_list = SystemPhoto.objects.filter(code=code)
+        for i in pic_list:
+            data.append({
+                "pic_img":i.pic_img
+            })
+        data = json.dumps(data)
+        return HttpResponse(data)
+