Apply (if callable) or prepend (if a string) upload_to to the filename, then delegate further processing of the name to the storage backend. Until the storage layer, all file paths are expected to be Unix style (with forward slashes).
(self, instance, filename)
| 346 | setattr(cls, self.attname, self.descriptor_class(self)) |
| 347 | |
| 348 | def generate_filename(self, instance, filename): |
| 349 | """ |
| 350 | Apply (if callable) or prepend (if a string) upload_to to the filename, |
| 351 | then delegate further processing of the name to the storage backend. |
| 352 | Until the storage layer, all file paths are expected to be Unix style |
| 353 | (with forward slashes). |
| 354 | """ |
| 355 | if callable(self.upload_to): |
| 356 | filename = self.upload_to(instance, filename) |
| 357 | else: |
| 358 | dirname = datetime.datetime.now().strftime(str(self.upload_to)) |
| 359 | filename = posixpath.join(dirname, filename) |
| 360 | filename = validate_file_name(filename, allow_relative_path=True) |
| 361 | return self.storage.generate_filename(filename) |
| 362 | |
| 363 | def save_form_data(self, instance, data): |
| 364 | # Important: None means "no change", other false value means "clear" |