title: Django: Save user uploads in seperate folders
body: <p>I want individual users to be able to upload their files into a single folder (so each user has their own root folder, where they can upload their own files), but I am not sure of the best way to go about implementing this.</p>
  
  <p>I originally planned to use the users email as the their folder name, and all their uploads would be saved in this folder. However, from what I have gathered the only way of retrieving this information is through the request function, and I cannot manage to get an instance of request into the models.py file, and therefore cannot add it to my 'upload_to' directory.</p>
  
  <p>Any other ideas of how to separate users files, or how to get an instance of request in the models file would be greatly appreciated!!</p>
  
  <p>Here is my current model:</p>
  
  <pre><code>def user_directory_path(instance, filename):
      return 'user_{0}/{1}'.format(instance.user.id, filename)
  
  class UploadModel(models.Model):
      user = models.OneToOneField(User)
      file = models.FileField(upload_to=user_directory_path)
  </code></pre>
  
  <p>And it's associated error:</p>
  
  <pre><code>Exception Value: UploadModel has no user.
  </code></pre>