1👍
✅
This is really a question about upload_to
. That attribute also takes a callable, which is passed the instance and the filename:
def upload_to_book_path(instance, filename):
return 'uploads/' + instance.chapter.book.name + '/chapter/' + filename
class ChapterImages(models.Model):
image = models.ImageField(upload_to=upload_to_book_path)
Source:stackexchange.com