Commits

Anonymous committed 34e4fa1

Fixing troubles with multiupload and syntax errors

  • Participants
  • Parent commits f12799c

Comments (0)

Files changed (1)

 
     def save(self, name, content, save=True):
         name = self.gen_filename(name)
-        try:
-            model = self.field.model
-            old_image = model.objects.get(pk=self.instance.pk)
-            old_path = getattr(old_image, self.field.attname)
-            if self.storage.exists(old_path):
-                self.storage.delete(old_path)
-            self.delete_previews(old_path.name)
-        except:
-            pass
+        if self.instance.pk:
+            try:
+                model = self.field.model
+                old_image = model.objects.get(pk=self.instance.pk)
+                old_path = getattr(old_image, self.field.attname)
+                if self.storage.exists(old_path):
+                    self.storage.delete(old_path)
+                self.delete_previews(old_path.name)
+            except:
+                pass
         super(ExtendedImageFieldFile, self).save(name, content, save)
         self.add_previews(name, content)
     
         image_name = name.split('/')[-1:][0].replace(image_format, '')
         for preview in self.field.previews:
             if self.field.dir_sort:
-                preview_name = ('/').join([self.field.upload_to, '%ss' % preview['name'], '%s%s' % (image_name + image_format)]) 
+                preview_name = ('/').join([self.field.upload_to, '%ss' % preview['name'], '%s%s' % (image_name, image_format)]) 
             else:
                 preview_name = ('/').join([self.field.upload_to, '%s_%s%s' % (image_name, preview['name'], image_format)]) 
             if self.storage.exists(preview_name):