Ticket #5655: 5655.patch
File 5655.patch, 1.6 KB (added by , 17 years ago) |
---|
-
django/db/models/base.py
380 380 return os.path.getsize(self._get_FIELD_filename(field)) 381 381 382 382 def _save_FIELD_file(self, field, filename, raw_contents, save=True): 383 directory = field.get_directory_name() 384 try: # Create the date-based directory if it doesn't exist. 383 filename = field.get_filename(filename) 384 385 # Create the directory if it doesn't exist. 386 directory = os.path.split(filename)[0] 387 try: 385 388 os.makedirs(os.path.join(settings.MEDIA_ROOT, directory)) 386 389 except OSError: # Directory probably already exists. 387 390 pass 388 filename = field.get_filename(filename)389 391 390 # If the filename already exists, keep adding an underscore to the name of391 # the file until the filename doesn't exist.392 # If the filename already exists, keep adding an underscore to the name 393 # of the file until the filename doesn't exist. 392 394 while os.path.exists(os.path.join(settings.MEDIA_ROOT, filename)): 393 try: 394 dot_index = filename.rindex('.') 395 except ValueError: # filename has no dot 396 filename += '_' 397 else: 398 filename = filename[:dot_index] + '_' + filename[dot_index:] 395 filename = '%s_%s' % os.path.splitext(filename) 399 396 400 397 # Write the file to disk. 401 398 setattr(self, field.attname, filename)