def __call__(self, instance, filename):
if self.populate_from is not None and not hasattr(instance, self.populate_from):<EOL><INDENT>raise AttributeError("<STR_LIT>".format(self.populate_from))<EOL><DEDENT>ext = filename.split('<STR_LIT:.>')[-<NUM_LIT:1>]<EOL>readable_name = slugify(filename.split('<STR_LIT:.>')[<NUM_LIT:0>])<EOL>if self.populate_from:<EOL><INDENT>readable_name = slugify(getattr(instance, self.populate_from))<EOL><DEDENT>if self.random_name:<EOL><INDENT>random_name = hashlib.sha256(<EOL>"<STR_LIT>".format(time.time(), random.random()).encode('<STR_LIT:utf-8>')<EOL>)<EOL>readable_name = random_name.hexdigest()<EOL><DEDENT>elif self.prefix is not None:<EOL><INDENT>readable_name = f'<STR_LIT>'<EOL><DEDENT>file_name = "<STR_LIT>".format(readable_name, ext)<EOL>return os.path.join(self.path, file_name)<EOL>
Generates an name for an uploaded file.