Browse Source

系通管理上传图片

Your Name 5 years ago
parent
commit
a170777fb1
1 changed files with 14 additions and 7 deletions
  1. 14 7
      apps/Equipment/views.py

+ 14 - 7
apps/Equipment/views.py

@@ -4608,7 +4608,7 @@ class System_Photo(ListView):
     def get(self,request):
         return render(request, 'backstageNet/systemSet/imageUpload.html', context={})
     def post(self,request):
-
+        upl_time = timezone.now() 
         basestr = request.FILES.get("upload")
         basestr1 = request.FILES.get("upload1")
         now_time = time.strftime('%Y%m%d%H%M%S', time.localtime(time.time()))
@@ -4620,19 +4620,26 @@ class System_Photo(ListView):
             base_dir = 'media/uploads1/'
             code = 2
             img = Image.open(basestr1)
+        if os.path.exists(base_dir) == False:
+            os.makedirs(base_dir)
         img.save(base_dir + now_time +".png")
-        pic_list = SystemPhoto.objects.filter(code=code).order_by("-upl_time")
+        pic_list = SystemPhoto.objects.filter(code=code).order_by("upl_time")
         if code == 1:
-            if pic_list and len(pic_list) <=2:
+            if 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")
+                for i in pic_list[:1]:
+                    i.pic_img=base_dir +now_time +".png"
+                    i.upl_time=upl_time
+                    i.save()
         else:
-            if pic_list and len(pic_list) <=3:
+            if 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")
-        
+                for i in pic_list[:1]:
+                    i.pic_img=base_dir +now_time +".png"
+                    i.upl_time=upl_time
+                    i.save()
         return HttpResponse("1")