title: Django: How to allow a Suspicious File Operation / copy a file
body: <p>I want to do a <code>SuspiciousFileOperation</code> which django disallows by default.</p>
  
  <p>I am writing a command (to run via <code>manage.py importfiles</code>) to import a given directory structure on the real file system in my self written filestorage in Django.</p>
  
  <p>I think, this is my relevant code:</p>
  
  <pre><code>def _handle_directory(self, directory_path, directory):
      for root, subFolders, files in os.walk(directory_path):
          for filename in files:
              self.cnt_files += 1
              new_file = File(directory=directory, filename=filename, file=os.path.join(root, filename),
                   uploader=self.uploader)
              new_file.save()
  </code></pre>
  
  <p>The backtrace is:</p>
  
  <pre><code>Traceback (most recent call last):
    File ".\manage.py", line 10, in &lt;module&gt;
      execute_from_command_line(sys.argv)
    File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 399, in execute_from_command_line
      utility.execute()
    File "C:\Python27\lib\site-packages\django\core\management\__init__.py", line 392, in execute
      self.fetch_command(subcommand).run_from_argv(self.argv)
    File "C:\Python27\lib\site-packages\django\core\management\base.py", line 242, in run_from_argv
      self.execute(*args, **options.__dict__)
    File "C:\Python27\lib\site-packages\django\core\management\base.py", line 285, in execute
      output = self.handle(*args, **options)
    File "D:\Development\github\Palco\engine\filestorage\management\commands\importfiles.py", line 53, in handle
      self._handle_directory(args[0], root)
    File "D:\Development\github\Palco\engine\filestorage\management\commands\importfiles.py", line 63, in _handle_directory
      new_file.save()
    File "D:\Development\github\Palco\engine\filestorage\models.py", line 157, in save
      self.sha512 = hashlib.sha512(self.file.read()).hexdigest()
    File "C:\Python27\lib\site-packages\django\core\files\utils.py", line 16, in &lt;lambda&gt;
      read = property(lambda self: self.file.read)
    File "C:\Python27\lib\site-packages\django\db\models\fields\files.py", line 46, in _get_file
      self._file = self.storage.open(self.name, 'rb')
    File "C:\Python27\lib\site-packages\django\core\files\storage.py", line 33, in open
      return self._open(name, mode)
    File "C:\Python27\lib\site-packages\django\core\files\storage.py", line 160, in _open
      return File(open(self.path(name), mode))
    File "C:\Python27\lib\site-packages\django\core\files\storage.py", line 261, in path
      raise SuspiciousFileOperation("Attempted access to '%s' denied." % name)
  django.core.exceptions.SuspiciousFileOperation: Attempted access to 'D:\Temp\importme\readme.html' denied.
  </code></pre>
  
  <p>The <a href="https://github.com/omeinusch/Palco/blob/master/engine/filestorage/models.py" rel="noreferrer">full model can be found at GitHub</a>. The <a href="https://gist.github.com/omeinusch/0c40f9a0e35f2e58adca/d1d2fd506c52065a24f3dfafa27410e1c24a5b11" rel="noreferrer">full command is currently on gist.github.com available</a>. </p>
  
  <p>If you do not want to check the model: the attribute <code>file</code> of my <code>File</code> class is a <a href="https://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.FileField" rel="noreferrer">FileField</a>.</p>
  
  <p>I assume, this problem happens, because I am just "linking" to the file found. But I need to copy it, huh? How can I copy the file into the file?</p>