Django file upload – How to check if filename already exists in disk

Use this solution to raise an error when the uploaded file has the same name as a previously stored file in system.

In the following code, the FileField is named my_file. The clean_my_file method ensures that the user will be informed if the filename already exists in the destination directory and will prevent the user from saving the file.