- Simple way to implement dynamic image upload_to path based on object.It is now possible for the
upload_toparameter of the
ImageFieldto be a callable, instead of a string. The callable is passed the current model instance and uploaded file name and must return a path.
val="Book_Media/" + str(instance.Books.no) + "/" + str(filename)
imagepath is the callable (in this case a function). It simply gets the 'no' from the instance of
Booksand uses that in the upload path. Images will be uploaded to paths like: Book_Media/1/djano.jpg