Ticket #6450: directory_creation.diff

File directory_creation.diff, 1.0 KB (added by henry <henry@…>, 17 years ago)
  • django/db/models/base.py

     
    382382        return os.path.getsize(self._get_FIELD_filename(field))
    383383
    384384    def _save_FIELD_file(self, field, filename, raw_contents, save=True):
    385         directory = field.get_directory_name()
    386         try: # Create the date-based directory if it doesn't exist.
    387             os.makedirs(os.path.join(settings.MEDIA_ROOT, directory))
    388         except OSError: # Directory probably already exists.
    389             pass
     385        directory = os.path.join(settings.MEDIA_ROOT,
     386                field.get_directory_name())
     387        if not os.path.exists(directory):
     388            os.makedirs(directory)
     389        elif not os.path.isdir(directory):
     390            raise IOError('%s exists and is not a directory' % directory)
    390391        filename = field.get_filename(filename)
    391392
    392393        # If the filename already exists, keep adding an underscore to the name of
Back to Top