Ticket #24105: files.patch

File files.patch, 1.1 KB (added by John Bowen, 10 years ago)
  • files.py

    old new  
    229229
    230230        self.storage = storage or default_storage
    231231        self.upload_to = upload_to
    232         if callable(upload_to):
    233             self.generate_filename = upload_to
    234232
    235233        kwargs['max_length'] = kwargs.get('max_length', 100)
    236234        super(FileField, self).__init__(verbose_name, name, **kwargs)
     
    311309        return os.path.normpath(self.storage.get_valid_name(os.path.basename(filename)))
    312310
    313311    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))
    315318
    316319    def save_form_data(self, instance, data):
    317320        # Important: None means "no change", other false value means "clear"
Back to Top