[Answer]-Uploading files to directory named by the value of a Foreign key field

1👍

class Photo(models.Model):
    .....
    photo = models.ImageField(upload_to=upload_photo_path_function)
    .....

def upload_photo_path_function(instance, filename):
    path = os.path.join('files/', instance.album.title)
    return path
👤DAKZH

Leave a comment