modified image storage.
authornishanth
Fri, 26 Feb 2010 15:15:16 +0530
changeset 118 5bbb29a07b87
parent 117 58fa1d626d37
child 119 39ab7c460143
modified image storage.
taskapp/models.py
--- a/taskapp/models.py	Fri Feb 26 15:00:01 2010 +0530
+++ b/taskapp/models.py	Fri Feb 26 15:15:16 2010 +0530
@@ -26,6 +26,13 @@
 IMAGES_DIR = "./images"
 UPLOADS_DIR = "./uploads"
 
+def get_key():
+    """ generate a 10 character name with random alphabets and digits.
+    """
+
+    name = ''.join([ random.choice(string.uppercase+string.digits) for i in range(10)])
+    return name
+
 class CustomImageStorage(FileSystemStorage):
 
     def path(self, name):
@@ -39,10 +46,10 @@
         """
     
         root, ext = os.path.splitext(name)
-        name = ''.join([ random.choice(string.uppercase+string.digits) for i in range(10)])+ext
-        while self.exists(name):
-            name = ''.join([ random.choice(string.uppercase+string.digits) for i in range(10)])+ext
-        return name
+        file_name = get_key() + ext
+        while self.exists(file_name):
+            file_name = get_key() + ext
+        return file_name
 
 class Profile(models.Model):