#26058: Custom storage backend's not entirely decoupled from FileField
-------------------------------------+-------------------------------------
Reporter: Korijn | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: File | Version: 1.9
uploads/storage |
Severity: Normal | Resolution:
Keywords: custom storage | Triage Stage: Accepted
filefield |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Korijn):
How's this?
{{{
def generate_filename(self, instance, filename):
# allow for customized filename generation
if hasattr(self.storage, 'generate_filename'):
if callable(self.upload_to):
filename = self.upload_to(instance, filename)
return self.storage.generate_filename(filename)
filename =
force_text(datetime.datetime.now().strftime(force_str(self.upload_to)))
return self.storage.generate_filename(filename)
# If upload_to is a callable, make sure that the path it returns
is
# passed through get_valid_name() of the underlying storage.
if callable(self.upload_to):
directory_name, filename =
os.path.split(self.upload_to(instance, filename))
filename = self.storage.get_valid_name(filename)
return os.path.normpath(os.path.join(directory_name,
filename))
return os.path.join(self.get_directory_name(),
self.get_filename(filename))
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26058#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/064.fbe0d75a7c58a74db89bf91b98049c7f%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.