[Answer]-Image upload through admin in Django

1👍

The function you pass into upload_to must have the form:

def get_upload_file_name(instance, filename):
    new_file_path_and_name = os.path.join(BASE_DIR, 'static', 'test.txt')
    return new_file_path_and_name

instance is the instance of the Image model you’re about to save. That means it has access to all of the other fields that have been populated. filename is the original name of the file that was uploaded. You may choose to use filename or simply return another path + name of your choice.

The official documentation for this is here.

👤huu

Leave a comment