In my case I allow user to upload an avatar picture and use user_id as filename, simply. So there will be 1.jpg, 2.jpg, etc.
However I found if I upload a new avatar for some account that already has one uploaded, let's say user #10, the new file will be named as "10_1.jpg". This is OKay, however I don't need it and I hope new file could overwrite the old one - it also saves some disk space anyway.
I googled and searched but couldn't find a clue. I was hoping there would be an option for ImageField or FileField but it's not there.
Thanks for help!
You should define your own storage, inherit it from FileSystemStorage, and override get_available_name function in it. The use this storage for your imagefield. Something like this:
Michael Gendin's solution above works great for Django 2.1 (Hello from 2018!). It is only necessary to add the "max_length" attribute to the "get_available_name" method: