Commits

Justin Driscoll  committed dfcd618

Added save_image method to ImageModel

  • Participants
  • Parent commits ca3e1d1

Comments (0)

Files changed (1)

File imagekit/models.py

             if spec.pre_cache:
                 prop = getattr(self, spec.name())
                 prop._create()
+                
+    def save_image(self, name, image, save=True):
+        if self._imgfield:
+            self._imgfield.delete(save=False)
+        if hasattr(image, 'read'):
+            data = image.read()
+        else:
+            data = image
+        content = ContentFile(data)
+        self._imgfield.save(name, content, save)
 
     def save(self, clear_cache=True, *args, **kwargs):
         is_new_object = self._get_pk_val() is None