1👍
✅
Sure. Just check the docs for upload_to
:
This may also be a callable, such as a function, which will be called
to obtain the upload path, including the filename.
Check this answer to see an example which you can easily adapt to your problem.
👤arie
0👍
One Example;
def image_path(self, uploaded_file_name):
prefix = 'documents/'
extension = os.path.splitext(uploaded_file_name)[-1]
if self.pk != None:
return prefix + str(self.pk) + extension
else:
tmp_name = str(uuid.uuid4())
self.temp_image = prefix + tmp_name + extension
return self.temp_image
image_upload = models.ImageField(upload_to=image_path, null=True, blank=True)
You should use python functions.
- [Answer]-How to delete all django media so I can start fresh?
- [Answer]-Django-haystack (xapian) autocomplete giving incomplete results
- [Answer]-Google Appengine / Django / NDB setup throws mysqldb error on server start
Source:stackexchange.com