Created
November 18, 2011 10:24
-
-
Save gameame/1376105 to your computer and use it in GitHub Desktop.
Revisions
-
gameame revised this gist
Nov 22, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,6 +10,6 @@ class MyModel(models.Model): import os, base64, datetime def _func(instance, filename): name, ext = os.path.splitext(filename) name = base64.urlsafe_b64encode(name.encode("utf-8") + str(datetime.datetime.now())) return os.path.join(path, name + ext) return _func -
gameame revised this gist
Nov 18, 2011 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,5 +11,5 @@ class MyModel(models.Model): def _func(instance, filename): name, ext = os.path.splitext(filename) name = base64.urlsafe_b64encode(name.encode("utf-8") + unicode(datetime.datetime.now())) return os.path.join(path, name + ext) return _func -
gameame created this gist
Nov 18, 2011 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ def unique_filename(path): """ Enforce unique upload file names. Usage: class MyModel(models.Model): file = ImageField(upload_to=unique_filename("path/to/upload/dir")) """ import os, base64, datetime def _func(instance, filename): name, ext = os.path.splitext(filename) name = base64.urlsafe_b64encode(name.encode("utf-8") + unicode(datetime.datetime.now())) return os.path.join(path, name, ext) return _func