title: Django encoding problems with path name
body: <p>I'm doing a Django project which expects non-ascii characters, like àéã, etc. So far I have been able to navigate well this encoding hell, but I'm having problems with path names of uploaded files.</p>
  
  <p>I have a model that reads thus:</p>
  
  <pre><code>class Property (models.Model):
      #...
      city = models.CharField(max_length = 100, choices = CITIES_LIST)
      pdf_file = models.FileField(upload_to = generateUploadPath)
  </code></pre>
  
  <p>The upload_to calls a function that creates the path to store the file, based on the city field (which is the field that can have non-ascii characters):</p>
  
  <pre><code>def generateUploadPath (instance, file):
      city = instance.city
      storage_path = r'Property\{city}\{file}'.format(city = city, file = file)
      return storage_path
  </code></pre>
  
  <p>This works well. The folders are created, if they do not exist, with the correct names, and the files are stored there correctly. Problem is, I have a post_save signal that reads said file and processes it in a particular way:</p>
  
  <pre><code>@receiver(signals.post_save, sender = Property)
  def fileProcessing (sender, instance, created, **kwargs):
  
      file_path = instance.pdf_file.path
      pdf_file = open(file_path, 'r')
  </code></pre>
  
  <p>Here's where the code breaks. If done like that, running a form the following error pops: <strong>UnicodeEncodeError</strong>: <em>'ascii' codec can't encode character u'\xe1' in position 7: ordinal not in range(128)</em>. If I, instead, force an encoding with:</p>
  
  <pre><code>file_path = instance.pdf_file.path.encode('utf-8')
  </code></pre>
  
  <p>I get the following error: <strong>IOError</strong>: <em>[Errno 2] No such file or directory: 'C:\Django_project\Storage\Property\Bras\xc3\xadlia\test_file.pdf'</em>, even though the folder is correctly created in Windows as '..\Property\Brasília\'.</p>
  
  <p>The entire project is in UTF-8, I'm using Python 2.7.11, Django 1.9.4, db is Postgres 9.5, with the database encoding also set to UTF-8. My <strong>models.py</strong> has <em># -*- coding: utf-8 -*-</em> on the top, with unicode_literals imported.</p>