Ticket #24105: files.patch
File files.patch, 1.1 KB (added by , 10 years ago) |
---|
-
files.py
old new 229 229 230 230 self.storage = storage or default_storage 231 231 self.upload_to = upload_to 232 if callable(upload_to):233 self.generate_filename = upload_to234 232 235 233 kwargs['max_length'] = kwargs.get('max_length', 100) 236 234 super(FileField, self).__init__(verbose_name, name, **kwargs) … … 311 309 return os.path.normpath(self.storage.get_valid_name(os.path.basename(filename))) 312 310 313 311 def generate_filename(self, instance, filename): 314 return os.path.join(self.get_directory_name(), self.get_filename(filename)) 312 if callable(self.upload_to): 313 directory_name, filename = os.path.split(self.upload_to(instance, filename) 314 filename = self.storage.get_valid_name(filename) 315 return os.path.join(directory_name, filename) 316 else: 317 return os.path.join(self.get_directory_name(), self.get_filename(filename)) 315 318 316 319 def save_form_data(self, instance, data): 317 320 # Important: None means "no change", other false value means "clear"