title: Efficiently saving a file by hash in Django
body: <p>I am working on a Django project. What I want the user to be able to do is upload a file (through a Form) and then save the file locally to a custom path and with a custom filename - its hash. The only solution I can think of is by using the "upload_to" argument of the FileField I'm using. What this translates to (I think):</p>
  
  <p>1) Write the file to disk</p>
  
  <p>2) Calculate hash</p>
  
  <p>3) Return path + hash as filename</p>
  
  <p>The problem is that there are two write operations: one when saving the file from memory to disk to calculate the hash, and another one when actually saving the file to specified location.</p>
  
  <p>Is there a way to override FileField's save to disk method (or where can I find exactly what's going on behind the scenes) so that I can basically save the file using a temporary name and then rename it to hash, instead of having it be saved twice.</p>
  
  <p>Thanks.</p>