MCPcopy
hub / github.com/django/django / generate_filename

Method generate_filename

django/db/models/fields/files.py:348–361  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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"

Calls 5

validate_file_nameFunction · 0.90
callableFunction · 0.85
upload_toMethod · 0.45
nowMethod · 0.45
joinMethod · 0.45